SQL Server Performance Forum – Threads Archive
SQL – Strings with spaces –
Hi i am tryin with the following query and it throws error ,<br /><br />master..xp_cmdshell ‘dir C![Stick Out Tongue :p :p](styles/default/xenforo/smilies/tongue.png)
![Stick Out Tongue :p :p](styles/default/xenforo/smilies/tongue.png)
Try this
Declare @s varchar(100)
set @s=”’Dir C
![Stick Out Tongue :p :p](styles/default/xenforo/smilies/tongue.png)
print (@s) shows ‘Dir C
![Stick Out Tongue :p :p](styles/default/xenforo/smilies/tongue.png)
operable program or batch file.
NULL
?? any idea rajiv
NewBie-23
Remove after Files
Declare @s varchar(100)
set @s=’Dir C
![Stick Out Tongue :p :p](styles/default/xenforo/smilies/tongue.png)
Exec master..xp_cmdshell @s
Madhivanan Failing to plan is Planning to fail
Again it throws error,
file not found, now its actually lookin in C: drive not c
![Stick Out Tongue :p :p](styles/default/xenforo/smilies/tongue.png)
NewBie-23
That’s not the proper formatting for long file names on a command line. If a path on the command line does not comply to the 8.3 format, you delimit the path with double-quote characters:
DIR "C
![Stick Out Tongue :p :p](styles/default/xenforo/smilies/tongue.png)
![Stick Out Tongue :p :p](styles/default/xenforo/smilies/tongue.png)
Make sure this gives you the correct result Exec master..xp_cmdshell ‘Dir C
![Stick Out Tongue :p :p](styles/default/xenforo/smilies/tongue.png)
Madhivanan Failing to plan is Planning to fail
Thanks Adriaan
The new code is Declare @s varchar(100)
set @s=’Dir C:"Program’+’ ‘+’Files"’
Exec master..xp_cmdshell @s
Madhivanan Failing to plan is Planning to fail
Madhivanan/Adriaan , Thanks guys it works !! rajiv
NewBie-23
quote:Originally posted by Madhivanan
Thanks Adriaan
The new code is Declare @s varchar(100)
set @s=’Dir C:"Program’+’ ‘+’Files"’
Exec master..xp_cmdshell @s
Madhivanan Failing to plan is Planning to fail
Madhivanan,
Why are you treating blank spaces in strings in a special way?
Trust me, The new code is Declare @s varchar(100)
set @s=’Dir C:"Program’+’ ‘+’Files"’
Exec master..xp_cmdshell @s
Madhivanan Failing to plan is Planning to fail
set @s=’Dir C:"Program’+’ ‘+’Files"’ is just a difficult way of writing
set @s=’Dir C:"Program Files"’
EDIT:
Actually you’re putting the double-quote characters in the wrong places. The whole path must be between the double-quotes, not only the part of it that is not in the 8.3 format. My last example is incorrect, it shoud read:
set @s=’Dir "C
![Stick Out Tongue :p :p](styles/default/xenforo/smilies/tongue.png)
>>Why are you treating blank spaces in strings in a special way? Yes
I think He just wanted for an example >>set @s=’Dir "C
![Stick Out Tongue :p :p](styles/default/xenforo/smilies/tongue.png)
Madhivanan Failing to plan is Planning to fail
Sorry, yes now I see you were just elaborating on Rajiv’s code.
hi,
this can be achieved using space() also — as you are looking for blank spaces Declare @s varchar(100)
set @s=’Dir "C
![Stick Out Tongue :p :p](styles/default/xenforo/smilies/tongue.png)
Exec xp_cmdshell @s
print @s
HTH
regards hsGoswami
[email protected]
"Humans don’t have Caliber to PASS TIME , Time it self Pass or Fail Humans" – by Hemant Goswami
quote:Originally posted by ghemant
hi,
this can be achieved using space() also — as you are looking for blank spaces Declare @s varchar(100)
set @s=’Dir "C
rogram’+space(1)+’Files"’
Exec xp_cmdshell @s
print @s
HTH
regards hsGoswami
[email protected]
"Humans don’t have Caliber to PASS TIME , Time it self Pass or Fail Humans" – by Hemant Goswami
It can be achieved that way, sure. But what’s the point?
this can be achieved using space() also — as you are looking for blank spaces Declare @s varchar(100)
set @s=’Dir "C
![Stick Out Tongue :p :p](styles/default/xenforo/smilies/tongue.png)
Exec xp_cmdshell @s
print @s
HTH
regards hsGoswami
[email protected]
"Humans don’t have Caliber to PASS TIME , Time it self Pass or Fail Humans" – by Hemant Goswami
Hi,
quote:It can be achieved that way, sure. But what’s the point?
dear sir,
i m just giving my opinion about space() function as originator is trying to do some tweak using space ….. i appologizes if you are hurted but my intention was only to draw attention of originator about space().
[:I] hsGoswami
[email protected]
"Humans don’t have Caliber to PASS TIME , Time it self Pass or Fail Humans" – by Hemant Goswami
No one’s hurt, really.[<img src=’/community/emoticons/emotion-5.gif’ alt=’
![Wink ;) ;)](styles/default/xenforo/smilies/wink.png)
]]>