Select Into

hi

How do I use select into based on local variable with prefix.

Sample Code;

Declare @CompanyName as varchar(50)

Set @CompanyName = 'CompanyA'

Select A,B,C into Staging_ + @CompanyName from tableA

Thanks a lot

it doesn't allow me to create a table based on local variable. How should go about it? Thanks

try this

Declare @CompanyName as varchar(50)
Declare @Query as nvarchar(250)

Set @CompanyName = 'CompanyA'

set @Query = 'Select A,B,C into Staging_' + @CompanyName +' from tableA'
execute sp_executesql @Query

Thanks a lot