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 2012 Forums
 SQL Server Administration (2012)
 set default value if empty

Author  Topic 

magmo
Aged Yak Warrior

558 Posts

Posted - 2014-12-11 : 03:38:23
Hi

I have a stored procedure thattake the following parameter..

@GenderID nVarChar(500

I need to check if that value is '' and if so set it to '0'. How can I do that?

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-12-11 : 08:19:57
[code]SET @GenderID = CASE WHEN @GenderID = '' THEN '0' ELSE @GenderID END;[/code]You might also want to set it to something if it is null. A similar check can do that, or more compactly[code]SET @GenderID = COALESCE(NULLIF(@GenderID,''),'0')[/code]
Go to Top of Page

magmo
Aged Yak Warrior

558 Posts

Posted - 2014-12-11 : 09:51:58
Thanks a lot!
Go to Top of Page
   

- Advertisement -