Case Statements SQL

15 pts.
Tags:
CASE statement
SQL
I'm running a query that returns a specific status code. However, within my query that specific status doesn't always exist and I get a null value. I would like to return another status when that is the case. I can't seem to get the case statement to work.

Software/Hardware used:
Microsoft SQL

Answer Wiki

Thanks. We'll let you know when a new response is added.

If I understand correctly your situation, there is no need of a case statement.

You can use the <a href=”http://msdn.microsoft.com/es-es/library/ms184325.aspx”>ISNULL</a> or <a href=”http://msdn.microsoft.com/en-us/library/ms190349.aspx”>COALESCE</a> functions.

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Wilso011
    I don't believe those functions will work because the null isn't found oin a specific table. Not sure if posting the query will help: select A.*, B.Status, B.Date from (select h.hawbnum as HAWB#, h.cust as Customer, h.originairport as Origin, h.destairport as Destination, s.stscode as Status, min(convert (char(10), s.stsdatetime, 101)) as Date from hawb as h left join statushistory as s on h.hawbnum=s.docnumlong where s.stscode='scanin' and h.cust='tigerdirtv' and h.dateshipped between '12/01/09' and '3/19/2010' and h.hawbnum=' 11804387' --and s.stsgroupcode='dst' group by h.hawbnum, h.cust, h.originairport, h.destairport, s.stscode)A left join (select h1.hawbnum, s1.stsgroupcode as Status, min(convert (char(10), s1.stsdatetime, 101)) as Date from hawb as h1 left join statushistory as s1 on h1.hawbnum=s1.docnumlong where s1.stsgroupcode='dst' and h1.hawbnum=' 11804387' group by h1.hawbnum, s1.stsgroupcode, s1.stscode)B on a.hawb#=b.hawbnum order by a.hawb# The result (shortened to make it fit) Origin Destination Status Date Status Date ORD ORD SCANIN 12/1/2009 NULL NULL Those last two columns i would like to bring in a value, when the original is null.
    15 pointsBadges:
    report
  • carlosdl
    Try this (replace <some status> and <some date> with appropriate values):
    select A.*, ISNULL(B.Status,<some status>), ISNULL(B.Date,<some date>) from
    ...
    ...
    order by a.hawb#
    68,525 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following