Link to home
Get AccessLog in
Avatar of WEhalt
WEhaltFlag 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
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Assuming your variables are single values...

INSERT INTO #STAT_GROUPS (Column1Name, Column2Name)
VALUES (@HOSPITAL, @GROUP1), (@DOCTOR, @GROUP1)
If you have another table with doctors and groups then

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

hth

Mike
Avatar of 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)
ASKER CERTIFIED SOLUTION
Avatar of DcpKing
DcpKing
Flag of United States of America image

Link to home
membership
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access
Avatar of WEhalt

ASKER

Apparently nothing.  I just tried it again and it worked.
:)  That's because it's the last day before a holiday and the Gremlins are conspiring against you :)

Have a good weekend

Mike