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
 HOW TO ESCAPE SPECIAL CHARACTERS IN OSQL

Author  Topic 

kgundava
Yak Posting Veteran

66 Posts

Posted - 2011-07-05 : 12:01:59
Hi All,

I have a scenario where i have to write the out put of a query to a file using OSQL.
Unfortunately for me , I am stuck here i.e i am not figure out how to escape special in the table name
DECLARE @CMDTEST VARCHAR(3000)
SELECT @CMDTEST = 'osql -E -S -Q"select * from QA..SAPR3."\BDL\BADHOST" " -o"E:\TEST_QUERY_OUTPUT.txt"'
print @CMDMINUS
EXEC master..XP_cmdshell @CMDTEST
Thanks...
This is the error it is writing into the output file
Level 15, State 1, Server OPDEV, Line 1
Incorrect syntax near '/BDL/BADHOST'.


instead of \BDL\BADHOST if i give some other table name(i.e. without special characters) , the query is working fine

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-07-05 : 12:25:26
Maybe
-Q"select * from QA..SAPR3.[\BDL\BADHOST] "


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-07-05 : 12:26:29
If \BDL\BADHOST is really a table name then try
[\BDL\BADHOST]


No, you're never too old to Yak'n'Roll if you're too young to die.

Go to Top of Page

kgundava
Yak Posting Veteran

66 Posts

Posted - 2011-07-05 : 14:45:09
Thanks a ton --->nigelrivett,webfred !!!! It worked!!!!
Go to Top of Page
   

- Advertisement -