Doing an "indirect" SQL SELECT - TechRepublic
Question
October 8, 2007 at 01:25 PM
ttobin100

Doing an “indirect” SQL SELECT

by ttobin100 . Updated 18 years, 4 months ago

Does anyone know how I can do an “indirect” SQL SELECT statement? (one in which the column to return from a table is not named explicitly, but is contained in a variable?)

For example, instead of this:

SELECT trailer FROM …. WHERE …

I need to be able to do something like this:

DECLARE @FieldName nVarChar(30)
SELECT @FieldName = ‘trailer’
SELECT @FieldName FROM … WHERE …

The third line in my example above doesn’t work like I need it to.

Thanks!

-tom

This discussion is locked

All Comments