I picked up some SQL similar to the following:
IF EXISTS(SELECT name FROM tempdb..sysobjects WHERE name Like N'#tmp%'
and id=object_id('tempdb..#tmp'))
DROP TABLE
into
select * from permTable
I need to add more data to #tmp before continuing with the processing:
insert into
select * from permTable2
But this gives errors because SQL suggested sizes and types for #tmp columns (for example, if permTable has a column full of ints, but permTable2 has a column with the same name but with NULL in one record, you get "Cannot insert a NULL value in column "IsPremium", table "tempdb.dbo. # tmp").
How do I get #tmp to have the types I want? Is this really bad practice?
source
share