help with this syntax

  • Hi,

    i'm quering the msdb..sysjobhistory and i'm having a job with the name of DB's.

    my question is how i can query when i have a job with the name of DB's while i do cursor on the job name?

    select step_name from msdb..sysjobhistory

    where step_name = DB's

    THX

  • Sorry, don't understand your question. Can you explain more?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • how i can run this syntax when i have a job name that called DB's

    this syntax not working because of the ' between the B and s

    select step_name from msdb..sysjobhistory

    where step_name = DB's

    and i don't want to do that because i'm using a cursor on all the jobs name

    select step_name from msdb..sysjobhistory

    where step_name = 'DB''s'

  • Have a look at the QUOTENAME function. It should do what you want.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • maybe you can hep me different approach

    i want to retrieve the last top 10 history job from the msdb..sysjobhistory for each job.

    how i can write this syntax?

    THX

  • I'd start by using RowNumber partitioned by the jobid and ordered by the date. Then you can select where that is <=10

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • can you help here with a little start example of the script that i'm looking for?

    THX

  • Have a look here. Example B is almost exactly what you want to do.

    http://msdn.microsoft.com/en-us/library/ms186734.aspx

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 8 posts - 1 through 7 (of 7 total)

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