1
votes

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?

2
Can you include the code that you're using to call SQLCMD? - Tom H
@Tom H.: I'm only testing it via the SQLCMD mode ATM. My point is, I've seen how to supply the variables, but want to know if SQLCMD supports user interaction like SQLPlus does. - OMG Ponies

2 Answers

2
votes

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);
1
votes

There is a free tool "SQLS*Plus" which is an SQL*Plus for SQL Server. Works with SQL Server 2000/2005 and 2008

Very flexible with data formatting (set lines size, pagesize, etc), variables (&, &&), spool, etc - light years better than isql, osql or sqlcmd

I downloaded SQLS*Plus from http://www.memfix.com