Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 null field on concatened code

Author  Topic 

mjimenezh
Yak Posting Veteran

81 Posts

Posted - 2014-01-28 : 11:04:08
Hi, I have a concated code from excel when I have to pick some values for db update, the problem is when one field is empty, this field is date type and I don't now how can I validate if UserDate_02 field is null or not, I get it from a cell in excel and later when I get all the code I update the db, this is the line :

UPDATE ITEMS SET UserField_01='AA',UserDate_01='01/28/2014',UserYesNo_01=1,UserDate_02=''WHERE LotNumber='134034143017297'and ItemCode='G22221'


Thanks in advance

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2014-01-28 : 11:17:41
Depends on whether or not your data column in sql server allows nulls. Assuming it does and when it is "blank" in excel then your sql code should do something like this:

UserDate_02 = NullIF('<DateFromExcel>','')

That way if an empty space comes from excel it will end up as NULL in the database.

Be One with the Optimizer
TG
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-01-29 : 04:16:45
if its excel formula you're asking about put a formula like this
=IF(LEN(CellName)=0,"NULL",CellName)



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -