Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2007
    Location
    Stalybridge, Manchester
    Posts
    273

    Unanswered: If nothing to return then show Zero

    I have this query in SQL Server that brings me back the Max number of weeks within a recordset. I have some that have no records in, how can I say in the code below that if its Null then show Zero?

    Code:
    SELECT Convert(varchar, Max([Weeks Waiting])) + ' Weeks' As [Max]
    FROM	jez.WL_DATA
    Thanks

  2. #2
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    change this:

    Max([Weeks Waiting])

    to this:

    coalesce(Max([Weeks Waiting]),0)

  3. #3
    Join Date
    Apr 2007
    Posts
    183
    SELECT Convert(varchar, Max([max])) + ' Weeks' As [Max]
    FROM (

    SELECT Max([Weeks Waiting]) As [Max]
    FROM jez.WL_DATA

    union all

    select 0
    ) AS d

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Interesting take on the question Peso, I like it
    George
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •