Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

SQL syntax error Expand / Collapse
Author
Message
Posted Tuesday, December 10, 2013 8:44 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, October 15, 2014 2:16 AM
Points: 85, Visits: 345
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
Post #1521560
Posted Tuesday, December 10, 2013 8:52 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 11:46 AM
Points: 13,078, Visits: 12,528
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)
Post #1521563
Posted Tuesday, December 10, 2013 8:54 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, October 10, 2014 7:48 AM
Points: 1,323, Visits: 619
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

Post #1521564
Posted Tuesday, December 10, 2013 9:08 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, October 15, 2014 2:16 AM
Points: 85, Visits: 345
Actually my value has the closing parameter. I must have have missed it when I copied the sql to paste on this forum
Post #1521569
Posted Tuesday, December 10, 2013 9:31 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 11:46 AM
Points: 13,078, Visits: 12,528
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)
Post #1521573
Posted Tuesday, December 10, 2013 9:42 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, October 15, 2014 2:16 AM
Points: 85, Visits: 345
Yes, I still have issue with error.
Post #1521578
Posted Tuesday, December 10, 2013 9:48 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 11:46 AM
Points: 13,078, Visits: 12,528
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)
Post #1521583
Posted Tuesday, December 10, 2013 10:19 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, October 15, 2014 2:16 AM
Points: 85, Visits: 345
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)
Post #1521593
Posted Tuesday, December 10, 2013 10:25 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 6:04 PM
Points: 3,749, Visits: 8,415
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.
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?

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1521595
Posted Tuesday, December 10, 2013 10:33 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, October 15, 2014 2:16 AM
Points: 85, Visits: 345
Thanks for your information but what should I do on this case?
Post #1521596
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse