1. If i do a select on sysjobs i get all the jobs created in the DB along with the job owner_sid. But i want to get the actual name of the job owner. How do i get it???
2. On creating a batch file using the BCP query i can get the output into an external file. But is there any way i can give the columns also for the same??
Query is like this...
bcp "select name as Jobs, owner_sid as JobOwner from msdb..sysjobs" queryout d:\Jobs.xls.
But in my excel sheet output i wont the get the column heading as Jobs and JobOwner which i get in OSQL.
Is there any solution???
Last edited by sandu_bangalore; 10-16-03 at 15:28.
Originally posted by ms_sql_dba
i thought the poster was asking how to include field name in the output of bcp, not how to get the login name for the owner sid...isn't it?
Yeah...my bad...but I would still think he'd want the real owner name...
damn identity columns...
Since your creating a file, it's probably going in to Excel..
So here ya go...You can expand on it
SELECT Data_Row FROM (
SELECT '"Owner","Job"' As Data_Row, 1 AS Row_Group
SELECT '"' + l.Name+ '","' + j.Name + '"', 2 AS Row_Group
FROM msdb..sysjobs j
INNER JOIN master..syslogins l
ON l.sid = j.owner_sid
) AS XXX
ORDER BY Row_Group