BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
NitinC
Fluorite | Level 6

 

I want to pass this command to SQL server but single quotes within single quotes are causing issues.

 

'SQLCMD -S serever -U user -P passwd -Q "Execute xyz.dbo.abc 111, '2017-10-10'"'

 

'

SQLCMD -S serever -U user -P passwd -Q

"

Execute xyz.dbo.abc 111,

'

2017-10-10

'

"

'

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@NitinC wrote:

 

I want to pass this command to SQL server but single quotes within single quotes are causing issues.

 

'SQLCMD -S serever -U user -P passwd -Q "Execute xyz.dbo.abc 111, '2017-10-10'"'

 

'

SQLCMD -S serever -U user -P passwd -Q

"

Execute xyz.dbo.abc 111,

'

2017-10-10

'

"

'

 


What issue? If SAS is throwing an error you might 1) show the error and 2) try replacing one single quote with two single quotes (NOT a double quote) to pass.

data junk;
   x=' This is an example of using SAS''s double single quote to resolve to one quote in data.';
run;

 

Not promising anything but

View solution in original post

4 REPLIES 4
ballardw
Super User

@NitinC wrote:

 

I want to pass this command to SQL server but single quotes within single quotes are causing issues.

 

'SQLCMD -S serever -U user -P passwd -Q "Execute xyz.dbo.abc 111, '2017-10-10'"'

 

'

SQLCMD -S serever -U user -P passwd -Q

"

Execute xyz.dbo.abc 111,

'

2017-10-10

'

"

'

 


What issue? If SAS is throwing an error you might 1) show the error and 2) try replacing one single quote with two single quotes (NOT a double quote) to pass.

data junk;
   x=' This is an example of using SAS''s double single quote to resolve to one quote in data.';
run;

 

Not promising anything but

NitinC
Fluorite | Level 6

I will try what you said. 

 

I will try tomorrow when I have access to the SAS,

This is my typical code.

data _null_;
x= 'SQLCMD -S serever -U user -P passwd -Q "Execute xyz.dbo.abc 111, '2017-10-10'"';

call symput('X', X);

run;

filename abc pipe &x.;

At this stage when I am creating file reference single quotes are causing it to fail. SQL server is very particular about where to use single and double quotes.

Idea is to execute SQL Server procs via SQLCMD utility and capture output. I know I can use SQL pass through but it is not executing procs correctly in some cases and I am in touch with SAS support.





 

 

Ksharp
Super User
Try this one :

filename abc pipe %sysfunc(quote(SQLCMD -S serever -U user -P passwd -Q "Execute xyz.dbo.abc 111, '2017-10-10'"))  ;



NitinC
Fluorite | Level 6

Sure, I will try this also.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1087 views
  • 0 likes
  • 3 in conversation