473,486 Members | 1,640 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

sqlcmd and escape characters

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
Nov 22 '07 #1
2 10300
Desmodromic (da*******@yahoo.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, es****@sommarskog.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
Nov 22 '07 #2
On Nov 22, 5:20 pm, Erland Sommarskog <esq...@sommarskog.sewrote:
Desmodromic (davies...@yahoo.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...@sommarskog.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
Nov 23 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
8512
by: BTnews | last post by:
Hi, Can anyone here point me at a definitive guide or tutorial about using escape characters when building SQL queries from user entered data? I'm especially interested in info on this in regard...
2
43771
by: Matthew Wieder | last post by:
In my previous post, I asked about a routine which prepares a string for an XPath query by taking care of escape characters. Unable to find a list, I'm now wondering assumign I enclose the...
7
96250
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %%...
18
7146
by: Steve Litvack | last post by:
Hello, I have built an XMLDocument object instance and I get the following string when I examine the InnerXml property: <?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1...
4
7455
by: Guadala Harry | last post by:
I need to place the following into a string... How can I properly escape the % " / < and > characters? <table width="100%" border="0" cellspacing="0" cellpadding="4px" class="hfAll"></Table> ...
12
9612
by: Jeff S | last post by:
In a VB.NET code behind module, I build a string for a link that points to a JavaScript function. The two lines of code below show what is relevant. PopupLink = "javascript:PopUpWindow(" &...
3
2217
by: Guadala Harry | last post by:
I'd like to know the answer to the following question so I can know what to expect with regard to other similar uses of escape characters and strings. While everything works fine - I'd like to know...
15
18277
by: pkaeowic | last post by:
I am having a problem with the "escape" character \e. This code is in my Windows form KeyPress event. The compiler gives me "unrecognized escape sequence" even though this is documented in MSDN....
131
9140
by: Lawrence D'Oliveiro | last post by:
The "escape" function in the "cgi" module escapes characters with special meanings in HTML. The ones that need escaping are '<', '&' and '"'. However, cgi.escape only escapes the quote character if...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7123
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7173
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6839
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5427
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4863
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
259
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.