Is there anyway anyone knows of that i can select columns using variable names without building an execute statement??
ie.
DECLARE @col varchar(10)
SELECT @col = "AuditID"
SELECT @Col FROM tblAudit
??
Anyhelp a bonus
Thanks
Daniel/
Printable View
Is there anyway anyone knows of that i can select columns using variable names without building an execute statement??
ie.
DECLARE @col varchar(10)
SELECT @col = "AuditID"
SELECT @Col FROM tblAudit
??
Anyhelp a bonus
Thanks
Daniel/
No, you can't.
DECLARE @Id varchar(20), @Table varchar(20), @Field varchar(20)
@SQL varchar(200)
SET @Field = 'MyField'
SET @Id = 'Id'
SET @Table = 'MyTable'
exec('SELECT ' + @Field + ' FROM ' + @Table + ' where id = ''' + @id + '''')
That is all
But original question is do this without building an execute statement.
So from what ppl are telling me.
even though we are now in version 2000
SQL Does not support (from transact)
Evaluated column names similar to the javascript Eval statement
Variable arrays of any dimensions ??
is this correct ?
Daniel G
You may try UDF in sql2k.
what is UDF ???
User defined functions.
i think i may get away with a UDF that does a case statement on the column name variable passed in ..
thanks for everyones help
Danielg