I mentioned here that SELECT INTO in Sql Server is functionally similar to CREATE TABLE AS in Oracle. Oracle also has SELECT INTO, but it is used for assigning query results to a variable.
Here is a PL/SQL code snippet:
declare MyVariable varchar2(20); Begin select ColumnName into MyVariable from MyTable where MyID = SomeInteger; dbms_output.put_line('Hello ' || MyVariable); End
In the above example, a column value for a particular record is assigned to MyVariable and printed out.
How do you assign select results into T-Sql variables in Sql Server then? Here is a code sample that does the same thing above:
declare @MyVariable varchar(20) select @MyVariable = ColumnName from MyTable where MyId = SomeInteger print 'Hello ' + @MyVariable