Skip to main content
added 3 characters in body
Source Link
Relaxed1
  • 123
  • 1
  • 6

I assume the best way to set my SSMS (SQL Server 2005) output file path during runtime of T-SQL, is to use SQLCMD mode.

How do I use environment variables (e.g. %systemroot%) in the code? The following bombs:

:set mypath %systemroot% :out mypath"\the_result$(mypath)"\the_result.txt" select * from myTab

In other words, when using SQLCMD not from the command line, but inside my T-SQL code. I just need to sort out the syntax.

(And also perhaps, though forum protocol is probably to ask it as separate questions:

  1. Is there an environment variable for the folder of this .sql / the working folder?

  2. How do I prevent the line counts to go to my output file also? )

Thanks!

I assume the best way to set my SSMS (SQL Server 2005) output file path during runtime of T-SQL, is to use SQLCMD mode.

How do I use environment variables (e.g. %systemroot%) in the code? The following bombs:

:set mypath %systemroot% :out mypath"\the_result.txt" select * from myTab

In other words, when using SQLCMD not from the command line, but inside my T-SQL code. I just need to sort out the syntax.

(And also perhaps, though forum protocol is probably to ask it as separate questions:

  1. Is there an environment variable for the folder of this .sql / the working folder?

  2. How do I prevent the line counts to go to my output file also? )

Thanks!

I assume the best way to set my SSMS (SQL Server 2005) output file path during runtime of T-SQL, is to use SQLCMD mode.

How do I use environment variables (e.g. %systemroot%) in the code? The following bombs:

:set mypath %systemroot% :out $(mypath)"\the_result.txt" select * from myTab

In other words, when using SQLCMD not from the command line, but inside my T-SQL code. I just need to sort out the syntax.

(And also perhaps, though forum protocol is probably to ask it as separate questions:

  1. Is there an environment variable for the folder of this .sql / the working folder?

  2. How do I prevent the line counts to go to my output file also? )

Thanks!

Source Link
Relaxed1
  • 123
  • 1
  • 6

SQLCMD mode: environment variable syntax?

I assume the best way to set my SSMS (SQL Server 2005) output file path during runtime of T-SQL, is to use SQLCMD mode.

How do I use environment variables (e.g. %systemroot%) in the code? The following bombs:

:set mypath %systemroot% :out mypath"\the_result.txt" select * from myTab

In other words, when using SQLCMD not from the command line, but inside my T-SQL code. I just need to sort out the syntax.

(And also perhaps, though forum protocol is probably to ask it as separate questions:

  1. Is there an environment variable for the folder of this .sql / the working folder?

  2. How do I prevent the line counts to go to my output file also? )

Thanks!