I have 3 variables, street and neighborhood that are required and can be null zip, zip comes up other than null the query below works, but if it comes null zip it does not work, how do I work if the zip is null?
In your db, is there a good reason for zip to not be null? If not, allow null values. If so, fix your applications so that null values can't be sent to your db.
Oh, by the way, I'm sure you know the old saying. You have your mandatory fields, I have my default values.
Marked as answer by alvaro_web on Dec 10, 2012 11:16 AM
alvaro_web
Member
121 Points
172 Posts
variable null sqlserver
Dec 10, 2012 01:41 AM|LINK
Using VS2010, aspnet, SQLServer2008, c #
I have 3 variables, street and neighborhood that are required and can be null zip, zip comes up other than null the query below works, but if it comes null zip it does not work, how do I work if the zip is null?
Address localizaEndereco acaoEndereco.ObterPrimeiro(l => l.street.Equals (street) && l.neighborhood.Equals (neighborhood) && l.zip.Equals (zip));
oned_gk
All-Star
31655 Points
6470 Posts
Re: variable null sqlserver
Dec 10, 2012 01:51 AM|LINK
try use coalesce
If ZIP=null MyZIP will be "-" else MyZIP=ZIP
Dan Bracuk
Contributor
3970 Points
1096 Posts
Re: variable null sqlserver
Dec 10, 2012 02:17 AM|LINK
Step back from your code and think.
In your db, is there a good reason for zip to not be null? If not, allow null values. If so, fix your applications so that null values can't be sent to your db.
Oh, by the way, I'm sure you know the old saying. You have your mandatory fields, I have my default values.