So, I have a table with fields protoid and dbname. I now want to create a table called foo with one field called foobar inside of every database (dbname). I then want to populate that field with the matching protoid. I have started with this, but feel like I have taken a wrong turn somewhere. Help?
wb
Code:
DECLARE @protoid int
DECLARE @dbname varchar(20)
DECLARE @count int
;with temp as (
select ROW_NUMBER() over(partition by proto_id order by proto_id) as rownumber, proto_id, dbname
from [dbDEMAPPING].[dbo].[tblDataConnect]
)
SELECT distinct @protoid=PROTO_ID
,@dbname=DBNAME
FROM temp where rownumber = 1
wb