Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Pass data between servers using t-sql or sqlcmd

Author  Topic 

mattt
Posting Yak Master

194 Posts

Posted - 2011-02-08 : 04:48:56
Hi,

I'm trying to write an automated sqlcmd script that creates two identical logins on two different servers. So the relevant steps go:

:connect primaryDb 

create login myuser with password='mypassword'
Go

:setvar SID sid from syslogins where name = 'myuser'

:connect secondaryDb

create login myuser with password='mypassword', sid=$(SID)
Go


Unfortunately the script fails at the step :setvar SID sid from syslogins where name = 'myuser'. I can't seem to find a valid syntax to allow setvar to accept the result of a SQL statement.

Is there a syntax for this? Or a workaround in t-sql or sqlcmd that doesn't involve using linked servers?

Cheers, Matt
   

- Advertisement -