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!

Possible to use variable as table name 3

Status
Not open for further replies.

TRACEYMARYLAND

Programmer
May 21, 2004
370
US
im trying to access a table but i want to determine what table to read

DECLARE
@TABLE_NAME NVARCHAR(50),
@COLUMN_NAME NVARCHAR(50)

select DISTINCT @COLUMN_NAME FROM @TABLE_NAME

But im getting error...saying define @TABLE_NAME

is it actually possible to do this

 
thread183-969274

This is an inefficient (and less secure) method of processing and should be avoided, but if you feel you must, see the thread link above.

Questions about posting. See faq183-874
 
Code:
DECLARE @TABLE_NAME NVARCHAR(50),
        @COLUMN_NAME NVARCHAR(50),
        @STR VARCHAR(200)
SET @STR = 'select Distinct ' + @COLUMN_NAME + ' FROM ' + @TABLE_NAME 
exec(@STR)
 
Thanks sister...My whole form program is dynamically i.e they build their own form....then they can enter their data.

Now they need to select windows...but i do not know what field they would currently be on...so im building that into form template.

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top