Skip to main content
2 of 2
broken link fixed
Glorfindel
  • 2.2k
  • 5
  • 18
  • 26

I think you need to output your results to a file and bring them back in. Something like this should help get you close to what you are looking for:

:setvar MyDir "C:\scripts"
:OUT $(MyDir)\test.txt
PRINT ':SETVAR ServerName ''' + @@SERVERNAME + ''''
GO
:OUT stdout
:r $(MyDir)\test.txt
GO
SELECT $(ServerName)

You can see more examples here.

SQLRockstar
  • 6.4k
  • 26
  • 48