SQL SELECT multi-columns INTO multi-variable

ala picture ala · Aug 27, 2009 · Viewed 130.8k times · Source

I'm converting SQL from Teradata to SQL Server

in Teradata, they have the format

SELECT col1, col2
FROM table1
INTO @variable1, @variable2

In SQL Server, I found

SET @variable1 = (
SELECT col1 
FROM table1
);

That only allows a single column/variable per statement. How to assign 2 or more variables using a single SELECT statement?

Answer

David M picture David M · Aug 27, 2009
SELECT @variable1 = col1, @variable2 = col2
FROM table1