views:

34

answers:

1

Hi All,

Is there a way to insert/update a datetime value (getdate()) into a temp table created like the following:

select id, null as testdate
into #temp_table

and then later statement:

update #temp_table 
set testdate=getdate()

i get error: "cannot convert datetime into int..."

Thanks, rod.

+6  A: 

Cast the column in the select into

select id, cast(null as datetime) as testdate
into #temp_table
Mike Forman
+1: Exactly. NULL by default in SQL Server is an INT; you need to CAST/CONVERT the NULL to the appropriate data type for the OP's stuff to work.
OMG Ponies
+1: Another example of why I always prefer to explicitly create my temp tables.
Joe Stefanelli