August 3, 2018 at 8:37 am
Hello,
I have this basic script. I get the following error when trying to insert values:
Msg 156, Level 15, State 1, Line 6
Incorrect syntax near the keyword 'values'.
I want to insert multiple rows of data into table columns.
create table ##Test ([Primary KW] varchar (100), [Secondary KW] varchar (100), [Teritary KW] varchar (100), [Quaternary KW] varchar (100))
insert into ##Test ([Primary KW],[Secondary KW], [Teritary KW], [Quaternary KW])
values ('red', '1','year old','car'),
values ('','2','','truck'),
values ('','3','','')
Not sure where the error is. Thx
August 3, 2018 at 8:56 am
VegasL - Friday, August 3, 2018 8:37 AMHello,I have this basic script. I get the following error when trying to insert values:
Msg 156, Level 15, State 1, Line 6
Incorrect syntax near the keyword 'values'.I want to insert multiple rows of data into table columns.
create table ##Test ([Primary KW] varchar (100), [Secondary KW] varchar (100), [Teritary KW] varchar (100), [Quaternary KW] varchar (100))
insert into ##Test ([Primary KW],[Secondary KW], [Teritary KW], [Quaternary KW])
values ('red', '1','year old','car'),
values ('','2','','truck'),
values ('','3','','')Not sure where the error is. Thx
You only specify the VALUES keyword once.
create table ##Test ([Primary KW] varchar (100), [Secondary KW] varchar (100), [Teritary KW] varchar (100), [Quaternary KW] varchar (100))
insert into ##Test ([Primary KW],[Secondary KW], [Teritary KW], [Quaternary KW])
values ('red', '1','year old','car'),
('','2','','truck'),
('','3','','')
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
August 3, 2018 at 9:12 am
The error message was telling you exactly what is wrong... you weren't using the VALUES Table Valued Constructor correctly.
create table ##Test ([Primary KW] varchar (100), [Secondary KW] varchar (100), [Teritary KW] varchar (100), [Quaternary KW] varchar (100))
insert into ##Test ([Primary KW],[Secondary KW], [Teritary KW], [Quaternary KW])
values ('red', '1','year old','car'),
('','2','','truck'),
('','3','','')
Do a Google search for "VALUES in sql server" to learn more.
You should also do a search on "Global Temporary Tables" and learn how they can destroy concurrency of code.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 3, 2018 at 9:23 am
Thanks for pointing me in right direction guys - Appreciate it.
I see the correct way to do it as:
create table ##Test ([Primary KW] varchar (100), [Secondary KW] varchar (100), [Teritary KW] varchar (100), [Quaternary KW] varchar (100))
insert into ##Test ([Primary KW],[Secondary KW], [Teritary KW], [Quaternary KW])
values ('red', '1','year old','car'), ('','2','','truck'), ('','3','','')
August 3, 2018 at 9:48 am
Heh... I didn't see Drew's post because I had opened this thread and let it sit for a while. So sorry for the double post with the same answer.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 3, 2018 at 9:52 am
Jeff Moden - Friday, August 3, 2018 9:48 AMHeh... I didn't see Drew's post because I had opened this thread and let it sit for a while. So sorry for the double post with the same answer.
But you had additional information about the global temp tables that I had missed.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy