Home Forums SQL Server 2008 SQL Server 2008 - General Use a variable as a column name - without dynamic SQL? RE: Use a variable as a column name - without dynamic SQL?
Steve Jones - SSC Editor
SSC Guru
Points: 734552
More actions
August 25, 2012 at 12:51 pm
#1530071
Not really. You can use a CASE type expressions as
...
If @item = 'Job'
then
select
JobID = OrderID
from #TblItems
else if @item = 'Order'
select OrderID = OrderID
from #tblItems