Avatar of WEhalt
WEhalt
Flag for United States of America asked on

SQL Insert Multiple Values with One Query

Is there a way to insert multiple rows with one insert?

INSERT INTO #STAT_GROUPS SELECT (@HOSPITAL, @GROUP1) UNION SELECT(@DOCTOR, @GROUP1)

#STAT_GROUPS only has 2 fields
Microsoft SQL ServerMicrosoft SQL Server 2008

Avatar of undefined
Last Comment
DcpKing

8/22/2022 - Mon
Jim Horn

Assuming your variables are single values...

INSERT INTO #STAT_GROUPS (Column1Name, Column2Name)
VALUES (@HOSPITAL, @GROUP1), (@DOCTOR, @GROUP1)
DcpKing

If you have another table with doctors and groups then

insert into #stat_groups
      select Doctor, Group
      from dbo.OtherTable

hth

Mike
WEhalt

ASKER
I do not have a table with the values, I am making one so I can create a cartesion product of options.

I cannot get this to work.  It keeps saying there is an error by the ',' .  All variables are just varchar(50) values.

INSERT INTO #STAT_GROUPS (CLAIM_LOC, CLAIM_PROC_DAYS_GRP)
VALUES (@HOSPITAL, @GROUP1), (@DOCTOR, @GROUP1)
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
DcpKing

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
WEhalt

ASKER
Apparently nothing.  I just tried it again and it worked.
DcpKing

:)  That's because it's the last day before a holiday and the Gremlins are conspiring against you :)

Have a good weekend

Mike