Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System() with sprintf

Status
Not open for further replies.

frangac

Technical User
Feb 8, 2004
163
ZA
Hi All,

How can I call a sprintf command to read the following

selcmd1=sprintf("%s","echo select A_NUM=nullif\(A_NUM,\\\" \\\"\) R_DT=date\('2006/06/06'\) "\\\\ngo | " opt)

in other words the result must return like :

echo select A_NUM=nullif\(A_NUM,\" \"\) where R_DT=date\('2006/06/06'\) \\ngo | /sybase_oc/OCS-12_0/bin/isql

It it those " ' " that I cannot get right. Without those quotes, awk thinks and does mathematical sums.
I need those in order to do a date function in Sybase.

Please help

Many Thanks
Chris
 
To get [!]echo select A_NUM=nullif\(A_NUM,\" \"\) where R_DT=date\('2006/06/06'\) \\ngo | /sybase_oc/OCS-12_0/bin/isql[/!] in selcmd1, provided opt="/sybase_oc/OCS-12_0/bin/isql":
selcmd1="echo select A_NUM=nullif\\(A_NUM,\\\" \\\"\\) where R_DT=date\\('2006/06/06'\\) \\\\ngo | " opt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Another option which would greatly simplify it (if it works in the context of your code) would be to just print the command and pipe it within awk, something along the lines of:

[tt]print "select A_NUM=nullif(A_NUM,\" \") where R_DT=date('2006/06/06') \ngo " | opt[/tt]

Annihilannic.
 
Hi PHV,

Thanks once again. I did try you solution but this is what I get

echo select A_NUM=nullif\(A_NUM,\" \"\) from CE.CDR_DRMS where R_DT=date\(2006/06/06\) and A_1=0 and A_2=1 and A_3=2 and A_4=3 and A_5=1 and A_6=1 and A_7=8 and A_8=8 and A_9=6 and A_10=isnull\(5,\"\"\) \\ngo | /sybase_oc/OCS-12_0/bin/isql -UDBA -PSQL -Sdrms_iq CHATAA
Msg 257, Level 16, State 0:
ASA Error -157: Cannot convert 55 to a date

I still thing that it is doing an mathematical sum.

Code:

function select_tablename(selcmd1,dc)
{
selcmd1="echo select A_NUM=nullif\\(A_NUM,\\\" \\\"\\) from CE.CDR_DRMS where R_DT=date\\([red]'[/red][blue]2006/06/06[/blue][red]'[/red]\\) and A_1="Dig1" and A_2="Dig2" and A_3="Dig3" and A_4="Dig4" and A_5="Dig5" and A_6="Dig6" and A_7="Dig7" and A_8="Dig8" and A_9="Dig9" and A_10=isnull\("Dig10",\\\"\\\"\) \\\\ngo | " opt
if (dc = system(selcmd1) != 0)
{
PLogmsg(2, "Failed ")
}
close(selcmd1)
system(selcmd1)
}

Instead of me doing a date conversion , how can I use with single quotes in the R_DT=('2006/06/06 [red]00:00:00[/red]')


Many Thanks
Chris
 
Hi All,

I have a solution but seems to be like PHV would call it 'BRUTE'

Da=`awk '{print $2" 00:00:00"}'`
and then

awk -v opt="/sybase_oc/OCS-12_0/bin/isql" -v opt2="'$Da'" '
{
.......
.......
}'

If any or better solution , please post

Many Thanks
Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top