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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Substring on a NULL value

Author  Topic 

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-04-24 : 08:41:42
I'm ata different location right now where I dont have access to SQL Server, so can't try it out myself.

This is the question.

I have an Insert statement like below

INSERT INTO TableA (City)
SELECT isnull(substring(AddressCity,1,21),'') from TableB

There are a few NULLs in AddressCity from TableB. Will the Substring fail on the NULL value? Or will the insert go through successfully. The "City" column in TableA is nullable.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-24 : 08:46:06
It will work.
Most (if not all) operations on a NULL column returns NULL.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-04-24 : 08:57:39
Thanks Peso.
Go to Top of Page

cat_jesus
Aged Yak Warrior

547 Posts

Posted - 2009-04-24 : 11:16:42
Keep in mind that the fastest way to figure that one out would have been to run just the select portion of the insert statement in SSMS. You could have even addeed "where addressCity is null " to the end of it to make it easier for you to see the results.






An infinite universe is the ultimate cartesian product.
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-04-24 : 11:28:14
Yeah could have done that. But like I mentioned already (which I think you failed to notice) EDIT : no offence meant.

quote:
I'm ata different location right now where I dont have access to SQL Server, so can't try it out myself.


Go to Top of Page

cat_jesus
Aged Yak Warrior

547 Posts

Posted - 2009-04-24 : 11:31:09
I did fail to notice, sorry abou that.

:)




An infinite universe is the ultimate cartesian product.
Go to Top of Page
   

- Advertisement -