Select * Into #tmpTable From yourtable Select * From #tmpTable Drop Table #tmpTablemake sure to put the '#' before the tablename, indicating a temporary table.
>declare @Sql varchar(1000), @tnCartID int, @Category char(1), @Temp char(1000) >set @Temp = 'select CredID, State, Address from Credit..CreditInfo where CredID in ' + > '(select CredID from CartDetail inner Join CartContent on > CartDetail.CartContentID = CartContent.CartContentID and CartContent.CartID = 4' + > ' and CartContent.CreditCategory = ' >set @tnCartID = 4 >set @Category = 'L' > >SET @Sql = @Temp + quotename(@Category,char(34)) +')' > >execute (@Sql)>
>SET @Sql = 'select CredID, State, Address from Credit..CreditInfo where CredID in ' + > '(select CredID from CartDetail inner Join CartContent on > CartDetail.CartContentID = CartContent.CartContentID and CartContent.CartID = 4' + > ' and CartContent.CreditCategory = ''' + @Category +''')' > >execute (@Sql) >>