TSQL

  • Thread starter Thread starter Eduardo Rosa
  • Start date Start date
E

Eduardo Rosa

hi everbody,
there's some way to do a query in stored procedure with dynamic table name.
I think to do a join with table sysobjects, but I could't do this works.

that's not works:
Select ColumnName From @TableName

thanks a lot
 
declare @tableName varchar(128)
Declare @SQL varchar(1000)
set @tableName = 'user'
Set @SQL = 'Select * from [' + @tableName + ']'

Exec (@SQL)
GO

you can't use sp_ExecuteSql to do a parameter substituaion for tableName...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
 
Back
Top