Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting multiple values into a temporary table, SQL Server

I am using Microsoft SQL Server Management Studio, I am trying to run the following query to input values into a temporary table to use later:

CREATE TABLE #temptable
(colnumber varchar(15), dispcode varchar(10))

INSERT INTO #temptable (colnumber, dispcode)
VALUES 
('col5', '811'),
('col6', '817'),
('col7', '823'),
('col8', '825');

When running I get the following error:

Msg 102, Level 15, State 1, Line 50
Incorrect syntax near ','.

Which points to the line "('col5', '811'),"

Could anyone help me identify the problem here?

like image 214
user2643021 Avatar asked Aug 01 '13 16:08

user2643021


1 Answers

For SQL Server version <2008 use this:

INSERT INTO #temptable (colnumber, dispcode)
SELECT 'col5', '811'
UNION ALL SELECT 'col6', '817'
UNION ALL SELECT 'col7', '823'
UNION ALL SELECT 'col8', '825'
like image 154
OzrenTkalcecKrznaric Avatar answered Sep 28 '22 01:09

OzrenTkalcecKrznaric