Is there a way to find only unique entries for a search. Currently I am
looking for jobs that a run for a give database, but the script will
return multiple job entries for the same job if the database is
reference many times in that job, (once per reference) is there a way
to weed out the duplicates?
Thanks.
-Matt-
<code>
select sj.name
from msdb.dbo.sysjobs sj join msdb.dbo.sysjobsteps sjs
on sj.job_id = sjs.job_id
where sjs.database_name = 'database_name' order by 'name'
</code>Try,
select sj.name
from msdb.dbo.sysjobs sj
where exists (
select *
from msdb.dbo.sysjobsteps sjs
where sjs.database_name = 'database_name' and sjs.job_id = sj.job_id
)
order by 'name'
go
You can also use "DISTINCT" in the original statement.
AMB
"Matthew" wrote:
> Is there a way to find only unique entries for a search. Currently I am
> looking for jobs that a run for a give database, but the script will
> return multiple job entries for the same job if the database is
> reference many times in that job, (once per reference) is there a way
> to weed out the duplicates?
> Thanks.
> -Matt-
>
> <code>
> select sj.name
> from msdb.dbo.sysjobs sj join msdb.dbo.sysjobsteps sjs
> on sj.job_id = sjs.job_id
> where sjs.database_name = 'database_name' order by 'name'
> </code>
>|||Thanks
Works perfectly.
No comments:
Post a Comment