Insert 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 enter values ​​into a temporary table, which will be used 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 I start, I get the following error:

Msg 102, Level 15, State 1, Line 50
Invalid syntax next to ','.

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

Can someone help me identify the problem here?

+4
source share
1 answer

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' 
+12
source

Source: https://habr.com/ru/post/1494793/


All Articles