Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Variable in a string

Author  Topic 

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2009-01-30 : 14:49:34
Have following string:

exec('Select * from QTEMP.F55125') at AS400SRV_MSDASQL


Now I want to replace "F55125" with a variable. Not sure about the syntax:

declare @File nvarchar(10)
set @File = 'F55125'
exec('Select * from QTEMP. ???@File???') at AS400SRV_MSDASQL

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-30 : 14:52:54
DECLARE @sql varchar(100)

SET @sql = 'select * from qtemp..' + @file

EXEC(@sql)

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-31 : 08:23:30
why does your table change dynamically?
Go to Top of Page
   

- Advertisement -