Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 4729

Change Column values during an INSERT with sub-query

$
0
0

I have a Stored Procedure that looks like this:

INSERT INTO TableNew (Attr1, Attr2, Attr3)
SELECT Attr1, Attr2, Attr3 FROM  TableOld 
WHERE AttrID = @AttrID

AttrID is TableB PrimaryKey.

My question is that some Attributes from TableB have NULL values and I'd *love* to avoid carrying over those NULL values from TableOld to TableNew but that is beyond my SQL coding "ability"?

Assume Attr3 column in TableOld has a NULL value and I'd really like to avoid carrying that NULL value over to the new Table during the INSERT operation.

I think I need to add some kind of conditional statement in my Stored Procedure to interrogate selected column values and force some default values in the case of NULLs?

Another BIG related problem is the date. I have two dates in the original record, a Creation date column and a Modification date column. It's often the case that the original record was never modified so the Modification date remained NULL. Would there be a way to code some kind of 'default' date values when the original Modification date is NULL? Something like Dec 31 2000 at midnight?

Any help is appreciated.


Viewing all articles
Browse latest Browse all 4729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>