Monday, March 26, 2012

Incorrect syntax near the keyword "From"

Hi, I have Error when I write this SQL statement retrieving the non selected facilitator for a specific course:

The SQL statement:

SELECT facilitators.facilitator_id, facilitators.facilitator_name

FROM facilitators INNER JOIN

[transaction_ facilitators] ON facilitators.facilitator_id <> [transaction_ facilitators].trans_Facilitator_id

WHERE (NOT (facilitators.facilitator_id IN

(SELECT [transaction_ facilitators].trans_Facilitator_id

FROM [transaction_ facilitators]

WHERE [transaction_ facilitators].trans_Course_id = 2)))

GROUP BY facilitators.facilitator_id, facilitators.facilitator_name

ORDER BY facilitators.facilitator_id

Every thing goes right until I change this:

WHERE [transaction_ facilitators].trans_Course_id = 2

To

WHERE [transaction_ facilitators].trans_Course_id = @.course_id

It gives me this error:

Incorrect syntax near the keyword "From"

Any suggestion ??

hi, could it be that the @.course_id variable being passed is having the wrong value? coz, I think you're query is valid enough..|||

Will it give the error before it takes the value.

:( I don't know what to do..

Its not working its sth with the passing parameter.

HELP…

|||in that case then would you mind posting your code here? aside from the one you gave already, especially the one you are assigning value to your variable.|||

The " Incorrect syntax near the keyword "From" error is appear to me while im using the query builder .

The error while using the code appears to be :

Invalid index 0 for this SqlParameterCollection with Count=0.

And the cose id:

IfNot Page.IsPostBackThen

Me.SqlConn.Open()

Me.SqlDataAdapter_Get_FaciliInfo.SelectCommand.Parameters(0).Value = 1'Request.QueryString.Get("courseid")

Me.SqlDataAdapter_Get_FaciliInfo.Fill(Me.Dataset_Get_PopUpFaciliInfo)

Me.DataGrid_Get_Info.DataBind()

Me.SqlConn.Close()

EndIf

...

|||ah ic so could be that you no value is being passed on the parameter, so in effect in your WHERE clause doesn't have any value: i.e.g 'SELECT * FROM column=' <-- no value that's why there is a syntax error in FROM.. maybe nothing no value is passed to the courseid in the query string ? i.e.mypage.aspx?courseid= instead ofmypage.aspx?courseid=2?


|||

no its not that if you've noticed that i make it comment

Me.SqlDataAdapter_Get_FaciliInfo.SelectCommand.Parameters(0).Value = 1'Request.QueryString.Get("courseid")

And pass the parameter a value 1 and I still get the same error

|||ok let's try one more time is the following your query string for your commandtext?:

SELECT facilitators.facilitator_id,facilitators.facilitator_name

FROM facilitatorsINNER JOIN

[transaction_facilitators] ON facilitators.facilitator_id <> [transaction_facilitators].trans_Facilitator_id

WHERE (NOT(facilitators.facilitator_id IN

(SELECT [transaction_facilitators].trans_Facilitator_id

FROM [transaction_facilitators]

WHERE [transaction_facilitators].trans_Course_id = @.code_id)))

GROUP BY facilitators.facilitator_id,facilitators.facilitator_name

if so, change the @.code_id to ?(question mark) so that the resulting command text will be:

SELECT facilitators.facilitator_id,facilitators.facilitator_name

FROM facilitatorsINNER JOIN

[transaction_facilitators] ON facilitators.facilitator_id <> [transaction_facilitators].trans_Facilitator_id

WHERE (NOT(facilitators.facilitator_id IN

(SELECT [transaction_facilitators].trans_Facilitator_id

FROM [transaction_facilitators]

WHERE [transaction_facilitators].trans_Course_id = ?)))

GROUP BY facilitators.facilitator_id,facilitators.facilitator_name

ORDER BY facilitators.facilitator_id

the reason being the @.<var> is a sql server reserved naming convention for its variable, it(Sql) assumed then that you declare a variable of that name, however since it isn't declared(coz it is being passed) it doesn't know how to generate a plan and gives you a cryptic error in FROM..

|||See your original thread for answer.|||

:( That's unbelievable… its not working what is this… look I try this:

SELECT DISTINCT facilitators.facilitator_id, facilitators.facilitator_name

FROM facilitators INNER JOIN

[transaction_ facilitators] ON facilitators.facilitator_id <> [transaction_ facilitators].trans_Facilitator_id

WHERE (NOT (facilitators.facilitator_id IN

(SELECT [transaction_ facilitators].trans_Facilitator_id

FROM [transaction_ facilitators]

WHERE [transaction_ facilitators].trans_Course_id = @.course_id)))

ORDER BY facilitators.facilitator_id

Not Working the same error: "Incorrect syntax near the keyword "From"

"

And I try this:

SELECT DISTINCT facilitators.facilitator_id, facilitators.facilitator_name

FROM facilitators INNER JOIN

[transaction_ facilitators] ON facilitators.facilitator_id <> [transaction_ facilitators].trans_Facilitator_id

WHERE (NOT (facilitators.facilitator_id IN

(SELECT [transaction_ facilitators].trans_Facilitator_id

FROM [transaction_ facilitators]

WHERE [transaction_ facilitators].trans_Course_id = @.course_id)))

GROUP BY facilitators.facilitator_id, facilitators.facilitator_name

ORDER BY facilitators.facilitator_id

Not Working the same error: "Incorrect syntax near the keyword "From"

"

And I try this:

SELECT facilitators.facilitator_id, facilitators.facilitator_name

FROM facilitators INNER JOIN

[transaction_ facilitators] ON facilitators.facilitator_id <> [transaction_ facilitators].trans_Facilitator_id

WHERE (NOT (facilitators.facilitator_id IN

(SELECT [transaction_ facilitators].trans_Facilitator_id

FROM [transaction_ facilitators]

WHERE [transaction_ facilitators].trans_Course_id = ?)))

GROUP BY facilitators.facilitator_id, facilitators.facilitator_name

ORDER BY facilitators.facilitator_id

Not Working the same error: "Incorrect syntax near the keyword "From"

"

And I try this:

SELECT facilitators.facilitator_id, facilitators.facilitator_name

FROM facilitators INNER JOIN

[transaction_ facilitators] ON facilitators.facilitator_id <> [transaction_ facilitators].trans_Facilitator_id

WHERE (NOT (facilitators.facilitator_id IN

(SELECT [transaction_ facilitators].trans_Facilitator_id

FROM [transaction_ facilitators]

WHERE [transaction_ facilitators].trans_Course_id = ?)))

ORDER BY facilitators.facilitator_id

Not Working the same error: "Incorrect syntax near the keyword "From"

"

Nothing work what is this… is it a curse ?

I don't have more time :'(… HELP

|||this is really strange, even if you substitute the parameter to a literal value it will still give you the same error? Ok then how about isolating your sub query first, try running that one alone and pass a literal value.|||If you are literally copying and pasting your code, and are also literally copying and pasting your error message, then the error message and the code are not matching up.

This error message would have an uppercase FROM if it were being generated from the code you have supplied so far.

Incorrect syntax near the keyword "From"
I think you are looking in the wrong place for the code generating the error.
sql

No comments:

Post a Comment