January 22, 2009 at 8:26 am
I was getting an error when I tried to execute an INSERT statement from my code and it does not appear to be a bug in my code (although it might be); I'm presuming it is fixed for SQL Server 2005, is it?
Any relevant info would be appreciated.
Error message:
Incorrect Syntax near the Keyword
Related links:
January 22, 2009 at 8:27 am
can you post the insert statement, there is something wrong on the syntax according to the error 🙂
January 23, 2009 at 12:32 am
Well this is the CommandText passed from Visual Studio. Any idea how to get the SQL statement from Management Studio, if at all possible?
"INSERT INTO [teamwiki].[dbo].[task]\r ([category_FK1]\r ,[sub_category_FK2]\r ,[task_description]\r ,[priority_FK3]\r ,[status_FK4]\r ,[ideal_delivery_date]\r ,[latest_delivery_date]\r ,[task_deadline]\r ,[request_date]\r ,[requesting_user]\r ,[assigned_to]\r ,[managed_by]\r ,[implementor_notes]\r ,[attachment] \r ,[last_update]\r ,[in_use]\r VALUES @category, \r @sub_category,\r @task_description,\r @priority,\r
@status, \r @ideal_delivery_date,\r @latest_delivery_date,\r NULL,\r GETDATE(),\r @requesting_user,\r NULL,\r NULL,\r NULL,\r NULL,\r @in_use,\r @product)"string
January 23, 2009 at 12:54 am
What you can do in VS is build that up as a string, assign it to a variable, do a debug.print (or equivalent) to get the string that will be executed, and after that pass that variable to whatever method is doing the DB call./
So, (pseudocode):
string sSQL = "Insert into "
sSQL = sSQL & ... // build up SQL statement here
debug.print sSQL
sqlCmd.ExecuteNonQuery sSQL
That said, I believe your problem is that you're missing two brackets. One after the column list, one straight after the values keyword. As follows...
"INSERT INTO [teamwiki].[dbo].[task]\r
([category_FK1]\r
,[sub_category_FK2]\r
,[ideal_delivery_date]\r
,[latest_delivery_date]\r
,[task_deadline]\r
,[request_date]\r
,[requesting_user]\r
,[assigned_to]\r
,[managed_by]\r
,[implementor_notes]\r
,[attachment] \r
,[last_update]\r
,[in_use])\r
VALUES (@category, \r
@sub_category,\r
@task_description,\r
@priority,\r
@status, \r
@ideal_delivery_date,\r
@latest_delivery_date,\r
NULL,\r
GETDATE(),\r
@requesting_user,\r
NULL,\r
NULL,\r
NULL,\r
NULL,\r
@in_use,\r
@product)" string
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
January 23, 2009 at 1:07 am
Indeed, thx
🙂
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply