Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Testing for Not NULL 2

Status
Not open for further replies.

dndaughtery

Programmer
Jan 25, 2006
67
US
I need to write a query to insert from one table to another but I want to avoid inserting empty rows. This is what I'm trying:

Insert into TableA
Select * from TableB where Fieldname Not Null;

But this is incorrect. How can I check for null value?
 
where FieldName IS NOT NULL.

------
[small]select stuff(stuff(replicate('<P> <B> ', 14), 109, 0, '<.'), 112, 0, '/')[/small]
[banghead]
 
Or:

Select * from TableB where nullif(fieldName, '') is null

------
[small]select stuff(stuff(replicate('<P> <B> ', 14), 109, 0, '<.'), 112, 0, '/')[/small]
[banghead]
 
Question, you are inserting WHOLE rows, correct?

You seem to be only checking one column for a NULL, what if that column is NULL, but the rest of the row has data?

-SQLBill

Posting advice: FAQ481-4875
 
> Select * from TableB where nullif(fieldName, '') is null

Typo... should be IS NOT NULL [blush].

------
[small]select stuff(stuff(replicate('<P> <B> ', 14), 109, 0, '<.'), 112, 0, '/')[/small]
[banghead]
 
The way everything is set up there will never be an instance where the field will be null. If it is there is no way to check it, it's a foriegn key.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top