I have a temp table that needs the values of a Stored procedure. So the SP inserts 3 columns into the temp table, then I want to add a datetime to every row without modifying the SP.
Since I call the SP 3 times, each time with a different datetime, I can’t just update the whole temp table.
Any Suggestions?
DECLARE @temp TABLE ( id INT IDENTITY(1,1), Name VARCHAR(150), Address VARCHAR(25), Date DATETIME ) WHILE (@count>=@daysBack) BEGIN SET @date=DATEADD(dd, @count, GETDATE()) INSERT INTO @temp (Name,Address) EXEC[dbo].StoredProc@date --I Want to check for Null and insert the date there Update @temp SET Date=@date WHERE Date='' SET @count=@count-1
Yes. Create the temp table and in the added date column that does not have representation from your sproc put a default value constraint of getdate() or whatever date formula you need. In the insert statement specify the columns explicitly and omit the date column and it should work. As the rows are added the default value constraint will kick in and fill that column for you.
example: