Elad Benda
Elad Benda

Reputation: 36682

TSQL - How to select some values from a table and some from SQL variables?

I want to return a table with columns names which are not defined somewhere else. Under these columns names I want the records to contain data from different sources: a table, a previously declared variable and a const.

What is the right syntax to do so?

i.e. columns names: "fromTable" (=select col1 from MyTable where id=1) , "fromVar" (=@MyVar), "fromConst"(=5).

thanks!

Upvotes: 0

Views: 98

Answers (1)

Sparky
Sparky

Reputation: 15125

Simply

select <columns>,@myVar as FromVar, '5' as FromConst
from table

Upvotes: 3

Related Questions