Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 10, 2012 02:17 AM by Dan Bracuk
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));
Dec 10, 2012 01:51 AM|LINK
try use coalesce
COALESCE(ZIP,'-') as MyZIP
If ZIP=null MyZIP will be "-" else MyZIP=ZIP
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.