Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Concatenation Work around

Author  Topic 

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2012-08-21 : 10:29:53
Hi,
I have this statement:
EXEC MASTER..XP_CMDSHELL 'sqlcmd -Usa -Ppass -dtest -h-1 -Q"set nocount on select distinct name from table where state = 'Available'" -oC:\temp\folder\registry.txt'

This above statement will be executed on the cmd line when I call the .sql file that ecompases it.
As you can see, the 'Available' condition appears to be unquoted due to the required single Quotes of xp_cmdshell.
Any idea how to work around this?
Thanks

--------------------------
Joins are what RDBMS's do for a living

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-08-21 : 10:38:07
EXEC MASTER..XP_CMDSHELL 'sqlcmd -Usa -Ppass -dtest -h-1 -Q"set nocount on select distinct name from table where state = ''Available''" -oC:\temp\folder\registry.txt'
Go to Top of Page

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2012-08-21 : 10:50:26
robvolk Thanks a lot, it does work when I executed the whole command.
I'm just curious why when I exclude the following select It does not work:
select distinct name from table where state = "Available"

can you please give a little explaination?
Thanks,

--------------------------
Joins are what RDBMS's do for a living
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-21 : 10:53:00
see

http://sqlblogcasts.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2012-08-21 : 11:15:18
quote:
Originally posted by visakh16

see

http://sqlblogcasts.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/


Thanks, interesting blog!

--------------------------
Joins are what RDBMS's do for a living
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-21 : 11:18:55
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -