views:

71

answers:

1

Coming from an Oracle background, Oracle's SQLPlus would let you indicate a variable. If the variable wasn't set, you'd be prompted to provide a value.

I'm using SQLCMD, using the $([var_name]) syntax. In SSMS SQLCMD mode, I get:

A fatal scripting error occurred.
Variable tbl_name is not defined.

...for trying to run:

SELECT COUNT(*) FROM $(tbl_name)

Does SQLCMD provide the same functionality as SQLPlus? If so, what am I doing wrong?

+1  A: 

SQLCMD does not support prompting for missing variable names. However, you can use SSMS in SQLCMD mode. Dunno how you're error was caused, but this works for me:

:setvar table "sys.tables"

SELECT * FROM $(table);

Greets Flo

Florian Reischl
I get the error cuz I'm not supplying the setvar portion.
OMG Ponies
SQLCMD does not support GUI behavior like SQLPlus. Maybe have a look at SQL-PowerShell.
Florian Reischl