Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Column Names From a Variable Without Execute Statement

Status
Not open for further replies.

GrahamHills

Programmer
Oct 4, 2002
28
GB
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



Thanks


 
For the benefit of those who are faced with the same problem, please be kind enough to:

1. Describe the problem.
2. Describe exactly what you did to solve the problem, preferably with sample code included.

That way, people who open this thread won't be disappointed when they expect to find an answer, or at least some discussion.

tks,
PH

 
I did not want to use the Execute statement because I needed to create some Dynamic SQL Statements from values within the "deleted" and "inserted" tables in a trigger. I acheived this by simply creating two temporary tables with the contactents of the above tables and then was above to use those in an Execute statement as follows:-


SELECT * INTO #MyDeleted FROM deleted
SELECT * INTO #MyInserted FROM inserted
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top