Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

assign Null value to a column Expand / Collapse
Author
Message
Posted Monday, July 29, 2013 1:01 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, October 22, 2013 2:21 PM
Points: 55, Visits: 526
In a result sql dataset if the value of a particular column is 0 i need to return Null, how do i approach write a query for that

Let's say i have 3 columns, Dept Name, Dept Division, Dept Count...Let say in my sql query if the Dept Count return 0 i should assign Null to it

Post #1478718
Posted Monday, July 29, 2013 1:16 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: 2 days ago @ 6:03 AM
Points: 1,240, Visits: 1,384
I would use a case statement to handle this.
Post #1478721
Posted Monday, July 29, 2013 1:16 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 3:06 PM
Points: 2,763, Visits: 5,904
You could use NULLIF(DeptCount, 0)
EDIT: Add reference http://msdn.microsoft.com/en-us/library/ms177562%28v=sql.90%29.aspx



Luis C.
I am a great believer in luck, and I find the harder I work the more I have of it. Stephen Leacock

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1478722
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse