Search code examples
sqlt-sqltemp-tables

Can I insert typed in values as well as selected data into a temporary table?


I want to create a temporary table that gives me a file spec. The table will be two columns; one with the column name (a value that is not in my db), the other is the values permitted in that column (in many cases these are values from the db). Is this possible? I've tried the below, which doesn't work, but might help to explain what I'm trying to do:

INSERT INTO #fileSpec (columnName,[value])

('myValue',table1.fieldName)
FROM dbo.table1
WHERE fieldDescription = 'criteria'

Solution

  • You can use insert . . . select:

    INSERT INTO #fileSpec (columnName,[value])
        SELECT 'myValue', table1.fieldName
        FROM dbo.table1
        WHERE fieldDescription = 'criteria';