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: Yesterday @ 10:16 AM
Points: 1,370, Visits: 1,545
I would use a case statement to handle this.
Post #1478721
Posted Monday, July 29, 2013 1:16 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

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



Luis C.
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

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