Inserting multiple values into a temporary table, SQL Server

66,215

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'
Share:
66,215
user2643021
Author by

user2643021

Updated on August 02, 2020

Comments

  • user2643021
    user2643021 almost 4 years

    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?