Here's my query:
IF Object_id('tempdb..##delist') IS NOT NULL
DROP TABLE ##delist
SELECT jl.jobid as 'JobID',
jl.CustomObjectName as 'DEName',
cols.name as 'ColumnName',
null as 'ColumnNumber'
INTO ##delist
FROM ##joblist AS jl WITH (nolock)
JOIN sys.tables tbls with (nolock) on tbls.name = jl.CustomObjectName
JOIN sys.columns cols with (nolock) on cols.object_id = tbls.object_id
WHERE cols.name <> '_CustomObjectKey'
Here's my result set:
What I'm ultimately looking for is a way to number the ColumnNumber data fields incrementally BY "DEName". So in other words, for every ColumnName for each DEName, I want the ColumnNumber to start at 1, and go to however many unique ColumnNames there are for each DEName. Any ideas?