Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SQL syntax error


SQL syntax error

Author
Message
eobiki10
eobiki10
SSC Journeyman
SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)

Group: General Forum Members
Points: 93 Visits: 369
Hi All,

Please I need help with this. I am having an error when I try to run a report that contains this code. The error is this "the Select list for the insert statement contains more items than the insert list. The number of select values must match the number of INSERT columns. Incorrect syntax near ','. " I have tried to have E.empl_uno IN (@employee) in the code but still the error persits. Any help will be appreciated.

INSERT INTO [BO_CUSTOM].[dbo].[Property_Coorindators]
([Employee_Uno]
,[Employee_Name]
,[Offc_Code]
,[Email]
Select @employee, employee_name, @Offc, EMAIL
from BO_live3.dbo.HBM_persnl E
where E.empl_uno = @employee
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16562 Visits: 17011
eobiki10 (12/10/2013)
Hi All,

Please I need help with this. I am having an error when I try to run a report that contains this code. The error is this "the Select list for the insert statement contains more items than the insert list. The number of select values must match the number of INSERT columns. Incorrect syntax near ','. " I have tried to have E.empl_uno IN (@employee) in the code but still the error persits. Any help will be appreciated.

INSERT INTO [BO_CUSTOM].[dbo].[Property_Coorindators]
([Employee_Uno]
,[Employee_Name]
,[Offc_Code]
,[Email]
Select @employee, employee_name, @Offc, EMAIL
from BO_live3.dbo.HBM_persnl E
where E.empl_uno = @employee


You are missing the closing parenthesis after the column list.


INSERT INTO [BO_CUSTOM].[dbo].[Property_Coorindators]
([Employee_Uno]
,[Employee_Name]
,[Offc_Code]
,[Email])
Select @employee, employee_name, @Offc, EMAIL
from BO_live3.dbo.HBM_persnl E
where E.empl_uno = @employee



_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Sarah Wagner
Sarah Wagner
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1560 Visits: 715
It appears that you are missing a ) after the fields you have listed

Insert into table1 (field1, field2) select fielda, fieldb from table2

http://www.w3schools.com/sql/sql_insert_into_select.asp
eobiki10
eobiki10
SSC Journeyman
SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)

Group: General Forum Members
Points: 93 Visits: 369
Actually my value has the closing parameter. I must have have missed it when I copied the sql to paste on this forum
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16562 Visits: 17011
eobiki10 (12/10/2013)
Actually my value has the closing parameter. I must have have missed it when I copied the sql to paste on this forum


So are you good to go then or do you still have an issue?

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
eobiki10
eobiki10
SSC Journeyman
SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)

Group: General Forum Members
Points: 93 Visits: 369
Yes, I still have issue with error.
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16562 Visits: 17011
eobiki10 (12/10/2013)
Yes, I still have issue with error.


So what is the EXACT query you are trying and what is the error message? This is probably incredibly simple to fix but we can't what you see.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
eobiki10
eobiki10
SSC Journeyman
SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)

Group: General Forum Members
Points: 93 Visits: 369
The error is this "the Select list for the insert statement contains more items than the insert list. The number of select values must match the number of INSERT columns. Incorrect syntax near ','. And the query is again

INSERT INTO [BO_CUSTOM].[dbo].[Property_Coorindators]
([Employee_Uno]
,[Employee_Name]
,[Offc_Code]
,[Email])
Select @employee, employee_name, @Offc, EMAIL
from BO_live3.dbo.HBM_persnl E
where E.empl_uno = @employee


SELECT *
FROM BO_custom.dbo.property_coorindators
WHERE offc_code IN (@Offc)
Luis Cazares
Luis Cazares
SSCrazy Eights
SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)

Group: General Forum Members
Points: 8525 Visits: 18123
The query doesn't seem to haev an error. However, there's something that intrigues me. You're using WHERE offc_code IN (@Offc) and seems that @Offc might be a comma-separated value.
If it's really a comma-separated value and you're building a string value for the query, then that might be the error, if you're not building the query on the fly, you might not get the correct value on your SELECT.


Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


How to post data/code on a forum to get the best help: Option 1 / Option 2
eobiki10
eobiki10
SSC Journeyman
SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)

Group: General Forum Members
Points: 93 Visits: 369
Thanks for your information but what should I do on this case?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search