Hui,
The Reason that's happening is because you are passing a Single quote in a 
field. The Direct SQL still runs through the ARS Engine. So, when the ARS 
engine sees a single quote in a field, it escapes it out, by adding another 
single quote, that way the database will recognize it as a normal character 
instead of a special character. SQL uses the ' to deliminate charcter values. 
The reason they do that is because if you wanted to save a Person record with a 
last name like O'Maley, it has to be sent to the database as O''Maley. So the 
ARS engine always escapes out a single quote in a field. It does this to "be 
helpful".
The only way to do this is to set the two parts into 2 separate fields 
(probably in a separate form, that way you can push the values in Phase 1, to 
get the values in place). Then call a stored Procedure, passing in the 2 
integer values, and have the stored procedure pull the second part of the Where 
clause from the second form and places that into a variable. Then execute the 
whole thing as 1 line:
execute ('Select SUM ((C3 - C901001003)/60 ) from T573 Where C901001003 >=' + 
@int_val_1 + ' AND C901001003 <=' + @int_val2 + ' AND C901002104 IS NOT NULL 
AND C901002116 NOT LIKE ''SALES%'' WHERE ' + @ProductCriteria)

The following:
@int_val_1
@int_val2
@ ProductCriteria

Are variables defined in the SQL Stored Procedure
The first 2:
@int_val_1
@int_val2
Could be passed into the Stored Procedure when you call it from ARS.

The next one down:
@ ProductCriteria
You need to define in the Stored Procedure and have the Stored Procedure pull a 
value into it via:
@ ProductCriteria = SELECT.....

We do have a RFC in to have the option on Direct SQL action to ignore the ' and 
not add an extra one to it.
They did have it working that way (it wouldn't add an extra ' ) in 7.0.0, but 
then "fixed it" in later version.

Hope That helps
Matt P.

________________________________
From: Action Request System discussion list(ARSList) [mailto:[EMAIL PROTECTED] 
On Behalf Of Bao, Hui-Qing
Sent: Monday, July 28, 2008 2:02 PM
To: [email protected]
Subject: Need help on passing parameter to direct SQL

Hello:

I have a Set Field active link action which is using direct sql to get a sum of 
difference between two fields. The sql statement is something like below:

Select SUM ((C3 - C901001003)/60 ) from T573 Where C901001003 >= $Start 
Date_int$ AND C901001003 <= $End Date_int$ AND C901002104 IS NOT NULL AND 
C901002116 NOT LIKE 'SALES%'  $Product Criteria$

 'Product Criteria' is a character field which will be set dynamically base on 
user action. I also have a Set Field action to 'build Product Criteria': " AND 
C300088000 = " +  " '"+ $Product Name$ +  "' "

The goal is to generate a sql statement like below:

Select SUM ((C3 - C901001003)/60 ) from T573 Where C901001003 >= 1154059200 AND 
C901001003 <= 1217217600 AND C901002104 IS NOT NULL C901002116 NOT LIKE 
'SALES%'  AND C300088000 = 'HUB LINE CARD'

But when I run the report I got sql error: "Failure during SQL operation to the 
database : Line 1: Incorrect syntax near 'Hub LINE CARD'."

When I check the database log, I saw system added a set of single quote round 
'HUB LINE CARD', the database log show the sql as

Select SUM ((C3 - C901001003)/60 ) from T573 Where C901001003 >= 1154059200 AND 
C901001003 <= 1217217600 AND C901002104 IS NOT NULL C901002116 NOT LIKE 
'SALES%'  AND C300088000 = ''HUB LINE CARD''

In Active link log, the value of 'Product Criteria' is:  AND C300088000 = 'HUB 
LINE CARD' , I don't know why system would add a set of single quote just 
around 'HUB LINE CARD'. We are using SQL server 2000.

Please help!!!

Hui

_____________________________________________________
This electronic message and any files transmitted with it contains
information from iDirect, which may be privileged, proprietary
and/or confidential. It is intended solely for the use of the individual
or entity to whom they are addressed. If you are not the original
recipient or the person responsible for delivering the email to the
intended recipient, be advised that you have received this email
in error, and that any use, dissemination, forwarding, printing, or
copying of this email is strictly prohibited. If you received this email
in error, please delete it and immediately notify the sender.
_____________________________________________________



__Platinum Sponsor: www.rmsportal.com ARSlist: "Where the Answers Are" html___

_______________________________________________________________________________
UNSUBSCRIBE or access ARSlist Archives at www.arslist.org
Platinum Sponsor: www.rmsportal.com ARSlist: "Where the Answers Are"

Reply via email to