SQLTeam.com | Weblogs | Forums

Select Into


#1

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


#3

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


#4

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


#5

Thanks a lot