SQL Case statement

  • select name,enabled,

    case

    when enabled = 1 then 'active'

    else 'notactive'

    end as JobStatus

    from msdb.dbo.sysjobs where name='JobName'

    Output:

    name enabled JobStatus

    JobName 1 active

    When the JobName job itself is not present I would still like to print out the underneath .It returns nothing as of now.But I need to print the underneath.

    If JobName1 is present print row 1 as underneath.

    if the JobName1 does not even exist then print row 2 as underneath.

    name            enabled                           JobStatus

    JobName1     1                                       active

    JobName2  SQL Job not present   SQLJob not present

    How do I do this

    • This topic was modified 3 years, 6 months ago by  mtz676.
  • this has already been discussed on https://www.sqlservercentral.com/forums/topic/case-statement-46 - if you need more/different info do follow it up there

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply