Dynamic SQL with Temporary Table

Posted: Saturday,April 4, 2009 in SQL 2005
Tags: , ,

Sometimes we’re using temporary table using #name. But it can’t be use inside dynamic query at SQL server. We must use ##name inside the query which is means we can use it out the dynamic query. Example :


create table tmp (id int identity(1,1) , name varchar(max))

insert into tmp values(‘Wihemdra’)
insert into tmp values(‘You’)

declare @strSql varchar(max)
set @strSql = ‘select * into ##x from tmp’
select * from ##x

Have A Nice Try.

Best Regards,



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s