Skip to main content
added 36 characters in body
Source Link
Thomas Stringer
  • 42.4k
  • 9
  • 119
  • 155

I think your best bet is to use dynamic SQL to accomplish this:

create procedure myprocedure
@tableName varcharnvarchar(50) = ''
as

    declare @sql_cmd nvarchar(200) 
    set @sql_cmd = 'select blah from ' + QUOTENAME(@tableName) + ' where blah = blah2'
    
    exec (@sql_cmd)

go

I think your best bet is to use dynamic SQL to accomplish this:

create procedure myprocedure
@tableName varchar(50) = ''
as

    declare @sql_cmd = 'select blah from ' + QUOTENAME(@tableName) + ' where blah = blah2'
    
    exec (@sql_cmd)

go

I think your best bet is to use dynamic SQL to accomplish this:

create procedure myprocedure
@tableName nvarchar(50) = ''
as

    declare @sql_cmd nvarchar(200) 
    set @sql_cmd = 'select blah from ' + QUOTENAME(@tableName) + ' where blah = blah2'
    
    exec (@sql_cmd)

go
added 11 characters in body
Source Link
Aaron Bertrand
  • 181.5k
  • 28
  • 402
  • 619

I think your best bet is to use dynamic SQL to accomplish this:

create procedure myprocedure
@tableName varchar(50) = ''
as

    declare @sql_cmd = 'select blah from ' + QUOTENAME(@tableName) + ' where blah = blah2'
    
    exec (@sql_cmd)

go

I think your best bet is to use dynamic SQL to accomplish this:

create procedure myprocedure
@tableName varchar(50) = ''
as

    declare @sql_cmd = 'select blah from ' + @tableName + ' where blah = blah2'
    
    exec (@sql_cmd)

go

I think your best bet is to use dynamic SQL to accomplish this:

create procedure myprocedure
@tableName varchar(50) = ''
as

    declare @sql_cmd = 'select blah from ' + QUOTENAME(@tableName) + ' where blah = blah2'
    
    exec (@sql_cmd)

go
Source Link
Thomas Stringer
  • 42.4k
  • 9
  • 119
  • 155

I think your best bet is to use dynamic SQL to accomplish this:

create procedure myprocedure
@tableName varchar(50) = ''
as

    declare @sql_cmd = 'select blah from ' + @tableName + ' where blah = blah2'
    
    exec (@sql_cmd)

go