dbTalk Databases Forums  

sqlcmd and escape characters

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss sqlcmd and escape characters in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Desmodromic
 
Posts: n/a

Default sqlcmd and escape characters - 11-22-2007 , 12:19 AM






The command below runs fine from within Management Studio

exec sp_MSforeachtable @command1="exec sp_spaceused '?' "

However, I'd like to run it via sqlcmd. I've tried various
combinations of escaping the doulbe and single quotes but without
success.

sqlcmd -E -Q "sp_MSforeachtable @command1=\"exec sp_spaceused '?'\""
Sqlcmd: 'exec sp_spaceused '?'\""': Unexpected argument. Enter '-?'
for help.


Any ideas?

Thanks,

\M

Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: sqlcmd and escape characters - 11-22-2007 , 02:20 AM






Desmodromic (davies_ms (AT) yahoo (DOT) com.au) writes:
Quote:
The command below runs fine from within Management Studio

exec sp_MSforeachtable @command1="exec sp_spaceused '?' "

However, I'd like to run it via sqlcmd. I've tried various
combinations of escaping the doulbe and single quotes but without
success.

sqlcmd -E -Q "sp_MSforeachtable @command1=\"exec sp_spaceused '?'\""
Sqlcmd: 'exec sp_spaceused '?'\""': Unexpected argument. Enter '-?'
for help.
Try:

sqlcmd -E -Q "sp_MSforeachtable @command1='exec sp_spaceused ''?'''"

In SQL you use ' delimit strings. " may also work as a string delimiter,
depending on the setting QUOTED_IDENTIFIER, but as this setting is normally
on, stick to ' and double it when nested.

--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #3  
Old   
Desmodromic
 
Posts: n/a

Default Re: sqlcmd and escape characters - 11-22-2007 , 06:30 PM



On Nov 22, 5:20 pm, Erland Sommarskog <esq... (AT) sommarskog (DOT) se> wrote:
Quote:
Desmodromic (davies... (AT) yahoo (DOT) com.au) writes:
The command below runs fine from within Management Studio

exec sp_MSforeachtable @command1="exec sp_spaceused '?' "

However, I'd like to run it via sqlcmd. I've tried various
combinations of escaping the doulbe and single quotes but without
success.

sqlcmd -E -Q "sp_MSforeachtable @command1=\"exec sp_spaceused '?'\""
Sqlcmd: 'exec sp_spaceused '?'\""': Unexpected argument. Enter '-?'
for help.

Try:

sqlcmd -E -Q "sp_MSforeachtable @command1='exec sp_spaceused ''?'''"

In SQL you use ' delimit strings. " may also work as a string delimiter,
depending on the setting QUOTED_IDENTIFIER, but as this setting is normally
on, stick to ' and double it when nested.

--
Erland Sommarskog, SQL Server MVP, esq... (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Excellent! Works fine and is just what I was looking for. Many thanks.

\M


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.