-
Column Names From a Variable Without Execute Statement
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/
-
-
Yes you can
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.
-
Summary
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.
-
-
-
udf
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|