Use sql function decode with Zend code

Hi,
I need to use sql function DECODE() in a query for PHP Code. This query works well in sql*plus but PHP returns
the following error message:
Parse error: syntax error, unexpected T_STRING in C:\Program Files\Zend\Apache2\htdocs\Compta\compta2.php on line 16
the query is :
$query =
'select substr(c.NUM,1 ,2) Compte ,
c.designation , a.Periode
,decode(substr(c.NUM,1 ,1), '1',1, '2',1,'3',1,-1) cp_type ,
sum(credit) - sum(debit) Montant
from ecritures a, clients b, compte c
where
b.NUM (+) =a.NUM
and a.DATEECRITURE between to_date(:debut, \'dd/mm/yy\') and to_date(:fin, \'dd/mm/yy\')
and substr(a.num,1,2) =c.num
group by substr(c.NUM,1 ,1), substr(c.NUM,1,2) , c.designation ,a.periode
order by compte ';
Can any one help me ???
Thanks by advance
nb: Iuse Zend 2.0

Hi,
You need to escape single quote mark:
decode(substr(c.NUM,1 ,1), \'1\',1, \'2\',1,\'3\',1,-1) cp_type ,
the same way you did for to_date:
to_date(:debut, \'dd/mm/yy\')
Regards,
Paweł

Similar Messages

  • Use SQL function to get the original order number using the invoice number

    Hi All,
    wondering is someone can help me with this challenge I am having?  Often I need to return the original order numbers that created the resulting invoce.  This is a relatively simple seriese of joins in a query but I am wanting to simplify it using a SQL function that can be referenced each time easily from with in the SELECT statement.  the code i currently have is:
    Use SQL function to get the original order number using the invoice number
    CREATE FUNCTION dbo.fnOrdersThatMakeInvoice(@InvNum int)
    RETURNS nvarchar(200)
    AS
    BEGIN
    DECLARE @OrderList nvarchar(200)
    SET @OrderList = ''
    SELECT @OrderList = @OrderList + (cast(T6.DocNum AS nvarchar(10)) + ' ')
    FROM  OINV AS T1 INNER JOIN
          INV1 AS T2 ON T1.DocEntry = T2.DocEntry INNER JOIN
          DLN1 AS T4 ON T2.BaseEntry = T4.DocEntry AND T2.BaseLine = T4.LineNum INNER JOIN
          RDR1 AS T5 ON T4.BaseEntry = T5.DocEntry AND T4.BaseLine = T5.LineNum INNER JOIN
          ORDR AS T6 ON T5.DocEntry = T6.DocEntry
    WHERE T1.DocNum = @InvNum
    RETURN @OrderList 
    END
    it is run by the following query:
    Select T1.DocNum, dbo.fnOrdersThatMakeInvoice(T1.DocNum)
    From OINV T1
    Where T1.DocNum = 'your invoice number here'
    The issue is that this returns the order number for all of the lines in the invoice.  Only want to see the summary of the order numbers.  ie if 3 orders were used to make a 20 line inovice I only want to see the 3 order numbers retuned in the field.
    If this was a simple reporting SELECT query I would use SELECT DISTINCT.  But I can't do that.
    Any ideas?
    Thanks,
    Mike

    Thanks Gordon,
    I am trying to get away from the massive table access list everytime I write a query where I need to access the original order number of the invoice.  However, I have managed to solve my own problem with a GROUP BY statement!
    Others may be interested so, the code is this:
    CREATE FUNCTION dbo.fnOrdersThatMakeInvoice(@InvNum int)
    RETURNS nvarchar(200)
    AS
    BEGIN
    DECLARE @OrderList nvarchar(200)
    SET @OrderList = ''
    SELECT @OrderList = @OrderList + (cast(T6.DocNum AS nvarchar(10)) + ' ')
    FROM  OINV AS T1 INNER JOIN
          INV1 AS T2 ON T1.DocEntry = T2.DocEntry INNER JOIN
          DLN1 AS T4 ON T2.BaseEntry = T4.DocEntry AND T2.BaseLine = T4.LineNum INNER JOIN
          RDR1 AS T5 ON T4.BaseEntry = T5.DocEntry AND T4.BaseLine = T5.LineNum INNER JOIN
          ORDR AS T6 ON T5.DocEntry = T6.DocEntry
    WHERE T1.DocNum = @InvNum
    GROUP BY T6.DocNum
    RETURN @OrderList 
    END
    and to call it use this:
    Select T1.DocNum, dbo.fnOrdersThatMakeInvoice(T1.DocNum)
    From OINV T1
    Where T1.DocNum = 'your invoice number'

  • Using DLL functions created with LabVIEW 6i in CVI 4.0.1

    I want use SQL functions from LabVIEW 6i in LabWindows/CVI 4.0.1. Building DLL with this LabVIEW-functions was succesfull, but after using DLL in CVI project and run, error message was generated: FATAL ERROR : LABVIEW.LIB was not called from a LabVIEW process. Can you help me? In attachment are VIs and build script for this DLL.
    Attachments:
    DLL.ZIP ‏24 KB

    The SQL toolkit appears to be an ActiveX program. Why not call the objects with activeX in CVI directly?
    There are several hits for labview.lib on ni's site. Goto http://search.ni.com/?col=alldocs&layout=TechResources&ql=a
    and search for labview.lib.

  • How to numberformat when using sql:query alogn with c:forEach JSTL tags

    Is there anyway to format the numeric values returned from the database when using <sql:query> alogn with <c:forEach> tags
    Here is my jsp code
    <sql:query..../>
    <c:forEach var="row" items="${queryResults.rows}">
    <tr>
    <td><c:out value="${row.COL1}" /></td>
    <td><c:out value="${row.COL2}" /></td>
    </tr>
    </c:forEach>
    Col1 values are numeric without any formats Eg: 1000, 10000, 1000000 etc.
    how can i format them to 1,000 , 10,1000 , 100,000 etc

    It is polite to mention what your answer was. These posts are not just here for you to ask questions, but to be used as a resource for other people to find answers. Saying "I solved it" with no details helps noone.
    I presume you discovered the JSTL <fmt:formatNumber> tag?

  • How to use SQL functions in the queries

    hey guys i wanna know how to use SQL functions in the queries is it possible or not .

    Hi,
    Wat exactly that set values are?
    those from sql query?
    How to use count():
    The COUNT() function returns the number of rows that matches a specified criteria.
    SQL COUNT(column_name) Syntax
    The COUNT(column_name) function returns the number of values (NULL values will not be counted) of the specified column:
    SELECT COUNT(column_name) FROM table_name
    SQL COUNT(*) Syntax
    The COUNT(*) function returns the number of records in a table:
    SELECT COUNT(*) FROM table_name
    SQL COUNT(DISTINCT column_name) Syntax
    The COUNT(DISTINCT column_name) function returns the number of distinct values of the specified column:
    SELECT COUNT(DISTINCT column_name) FROM table_name
    The IN function helps reduce the need to use multiple OR conditions.
    The syntax for the IN function is:
    SELECT columns
    FROM tables
    WHERE column1 in (value1, value2, .... value_n);

  • Using sql functions (min, max, avg) on varray or table collection

    Hi,
    I would like to know if there is a way to use sql function or oracle sql function like Min,Max, Avg or percentile_cont on varray or table collection ?
    Does anyone encountered this type of problem ?
    Thanks

    Yes you can apply Min,Max, Avg... if varray or table collection type is SQL (created in the databaase) UDF, not PL/SQL declared type:
    SQL> set serveroutput on
    SQL> declare
      2      type str_tbl_type is table of varchar2(4000);
      3      str_tbl str_tbl_type := str_tbl_type('X','A','D','ZZZ');
      4      max_val varchar2(4000);
      5  begin
      6      select max(column_value)
      7        into max_val
      8        from table(str_tbl);
      9      dbms_output.put_line('Max value is "' || max_val || '"');
    10  end;
    11  /
          from table(str_tbl);
    ERROR at line 8:
    ORA-06550: line 8, column 18:
    PLS-00642: local collection types not allowed in SQL statements
    ORA-06550: line 8, column 12:
    PL/SQL: ORA-22905: cannot access rows from a non-nested table item
    ORA-06550: line 6, column 5:
    PL/SQL: SQL Statement ignored
    SQL> create or replace type str_tbl_type is table of varchar2(4000);
      2  /
    Type created.
    SQL> declare
      2      str_tbl str_tbl_type := str_tbl_type('X','A','D','ZZZ');
      3      max_val varchar2(4000);
      4  begin
      5      select max(column_value)
      6        into max_val
      7        from table(str_tbl);
      8      dbms_output.put_line('Max value is "' || max_val || '"');
      9  end;
    10  /
    Max value is "ZZZ"
    PL/SQL procedure successfully completed.
    SQL> SY.

  • How to use SQL() function while writing scripts in BODS 4.0

    How to use SQL() function while writing scripts in BODS 4.0

    Hello,
    I think you want to post your question to the [Data Integration and Data Quality Management|Data Services and Data Quality; forum. This forum is for other BusinessObjects SDK development questions.
    Sincerely,
    Dan Kelleher

  • How to assign function module with process code in IDOC ?

    how to assign function module with process code in IDOC ? and what code i have to write in that function module for custom IDOC ?
    helpful answer will be rewarded?

    Hi,
    First goto transaction we42 -->editing mode --> new entries -->give name of your process code and description --> processing with alv service and function module -->then press enter -->after that enter the name of the function module you want to associate from the drop down and save it.
    Thats the way to assign function module with process code.
    In that process code we will have the Function modules and Bapi's which will take the data which we are sending through IDOC and then process it.
    for example: i am triggering the IDOC for every purchase order created then this process code in the receiver system will take the data which i have enetered in the sender system to create the purchase order and process it and creates the same purchase order in the receiver's system.
    Reward if helpful.
    with regards,
    Syed

  • Utils is a packege then should i use sql function in place of utils.

    Hi,
    while translating my sp from mssql to oracle few code is converted into : utils
    utils is a package i think so is it good to use it or should i find any sql equivenlent function.
    then please tel me oracle sql function for utils.patindex();
    yours sincerely

    Please bear in mind that most people here know Oracle but not SQL Server. So if you wish to use us as a translation service it would be helpful if you told us what the SQL Server function does.
    Googling for [url http://msdn.microsoft.com/en-US/library/ms188395(v=sql.90).aspx]PATINDEX() reveals that it is a function which returns the position of a pattern in a string. --The Oracle equivalent is INSTR().  [url http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions080.htm#sthref1174]Find out more.--
    Just to prove the point I now think INSTR() is the equivalent of CHARINDEX and what you actually want is one of the regex functions such as REGEXP_INSTR() [url http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions148.htm#sthref1419]Check it out.
    Oh, and please, don't use us as a translation service. Read the Oracle documentation or [url http://www.google.co.uk/#q=ms+sql+patindex+oracle&oq=ms+sql+patindex+oracle]use Google.
    Cheers, APC
    Edited by: APC on Feb 28, 2013 6:10 AM

  • Displaying Currency using SQL function

    I need to display amount with decimal point and 2 zeros when there are none .
    For eg $18 should be displayed as 18.00 ....
    Which sql function should be used to do this.
    Also is there any way to display Amount with commas .
    For eg 1800000 should be displayed as 1,800,000
    Any help in this regard is appreciated.

    To display the $18 like 18.00 I think you would use the TO_CHAR function like this
    TO_CHAR (retail,'$999.99') "retail price")
    and I believe for the commas just add commas in like
    TO_CHAR (retail,'$99,999,999.99') "retail price")
    Edited by: user12036877 on Oct 9, 2009 9:55 AM

  • Using Sql Functions in Crystal Reports

    Can SQL table-valued functions be used in Crystal Reports?  The only options I see in the Database Expert are Tables, Views, and Stored Procedures.

    Hi Dan,
    Are you referring to user-defined SQL functions? If yes, then these are not accessible in Crystal Reports.
    You would need to create a stored procedure which calls the function and does the processing and use this procedure in CR.
    - Abhilash

  • Using aggregate function along with for all entries: sugest alternative

    My requirement:
    For each record in i_vbap for which 'charg' is initial, need to determine batch using the following logic:
    For the material (MATNR) in i_vbap, select the batch (CHARG) which has the largest (MAX) unrestricted inventory quantity (CLABS) from MCHB table.
    How do I implement this logic without using select statement inside a loop as I cannot use MAX ( CLABS ) function along with FOR ALL ENTRIES in a SELECT?
    Suggest an alternative.

    For each record in i_vbap for which 'charg' is initial ,fetch all the existing 'clabs' value.
    [ Remember to include all the key fields in selct ]
    Sort the new table .
    Put a loop,use at end of 'charg' and append to another table. U get ur solution
    I think this should be the most economic way to do so.

  • Using SQL Server credentials with Secure Store Target Application for Data Connection in Dashboard Designer

    [Using SharePoint 2013 Enterprise SP1]
    I would like to use SQL Server credentials in a Secure Store Target Application, and
    this page makes it look like it's possible but when I attempt to use the new Target Application ID as authentication for a Data Connection in Dashboard Designer, I get a generic "Unable to access data source" with no error logged in SQL Server
    logs.
    I am able to use a Target Application with AD credentials to access the SQL db without a problem. Suggestions?

    Hi,
    1. Make sure that the credential is set to
    Secure Store Target Application. Navigate to the Central Administration. Click on the
    Application Management. Click on the Manage Service Applications. Click on the
    Secure Store Service Application. Select the application ID and from the ECB menu click on the
    Set Credentials. Enter the Credential Owner, Windows User Name and the
    Windows Password.
    2. Make sure that in the Dashboard Designer “Use a stored account” is selected in the “Authentication” and the proper application ID is mentioned.
    Please refer to the link below for more information:
    http://www.c-sharpcorner.com/Blogs/14527/unable-to-access-data-source-the-secure-store-target-applic.aspx
    Regards,
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected] .
    Rebecca Tu
    TechNet Community Support

  • Using analytical function - value with highest count

    Hi
    i have this table below
    CREATE TABLE table1
    ( cust_name VARCHAR2 (10)
    , txn_id NUMBER
    , txn_date DATE
    , country VARCHAR2 (10)
    , flag number
    , CONSTRAINT key1 UNIQUE (cust_name, txn_id)
    INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9870,TO_DATE ('15-Jan-2011', 'DD-Mon-YYYY'), 'Iran', 1);
    INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9871,TO_DATE ('16-Jan-2011', 'DD-Mon-YYYY'), 'China', 1);
    INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9872,TO_DATE ('17-Jan-2011', 'DD-Mon-YYYY'), 'China', 1);
    INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9873,TO_DATE ('18-Jan-2011', 'DD-Mon-YYYY'), 'Japan', 1);
    INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9874,TO_DATE ('19-Jan-2011', 'DD-Mon-YYYY'), 'Japan', 1);
    INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9875,TO_DATE ('20-Jan-2011', 'DD-Mon-YYYY'), 'Russia', 1);
    INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9877,TO_DATE ('22-Jan-2011', 'DD-Mon-YYYY'), 'China', 0);
    INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9878,TO_DATE ('26-Jan-2011', 'DD-Mon-YYYY'), 'Korea', 0);
    INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9811,TO_DATE ('17-Jan-2011', 'DD-Mon-YYYY'), 'China', 0);
    INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9854,TO_DATE ('13-Jan-2011', 'DD-Mon-YYYY'), 'Taiwan', 0);
    The requirement is to create an additional column in the resultset with country name where the customer has done the maximum number of transactions
    (with transaction flag 1). In case we have two or more countries tied with the same count, then we need to select the country (among the tied ones)
    where the customer has done the last transaction (with transaction flag 1)
    e.g. The count is 2 for both 'China' and 'Japan' for transaction flag 1 ,and the latest transaction is for 'Japan'. So the new column should contain 'Japan'
    CUST_NAME TXN_ID TXN_DATE COUNTRY FLAG country_1
    Peter 9811 17-JAN-11 China 0 Japan
    Peter 9854 13-JAN-11 Taiwan 0 Japan
    Peter 9870 15-JAN-11 Iran 1 Japan
    Peter 9871 16-JAN-11 China 1 Japan
    Peter 9872 17-JAN-11 China 1 Japan
    Peter 9873 18-JAN-11 Japan 1 Japan
    Peter 9874 19-JAN-11 Japan 1 Japan
    Peter 9875 20-JAN-11 Russia 1 Japan
    Peter 9877 22-JAN-11 China 0 Japan
    Peter 9878 26-JAN-11 Korea 0 Japan
    Please let me know how to accomplish this using analytical functions
    Thanks
    -Learnsequel

    Does this work (not spent much time checking it)?
    WITH ana AS (
    SELECT cust_name, txn_id, txn_date, country, flag,
            Sum (flag)
                OVER (PARTITION BY cust_name, country)      n_trx,
            Max (CASE WHEN flag = 1 THEN txn_date END)
                OVER (PARTITION BY cust_name, country)      l_trx
      FROM cnt_trx
    SELECT cust_name, txn_id, txn_date, country, flag,
            First_Value (country) OVER (PARTITION BY cust_name ORDER BY n_trx DESC, l_trx DESC) top_cnt
      FROM ana
    CUST_NAME      TXN_ID TXN_DATE  COUNTRY          FLAG TOP_CNT
    Fred             9875 20-JAN-11 Russia              1 Russia
    Fred             9874 19-JAN-11 Japan               1 Russia
    Peter            9873 18-JAN-11 Japan               1 Japan
    Peter            9874 19-JAN-11 Japan               1 Japan
    Peter            9872 17-JAN-11 China               1 Japan
    Peter            9871 16-JAN-11 China               1 Japan
    Peter            9811 17-JAN-11 China               0 Japan
    Peter            9877 22-JAN-11 China               0 Japan
    Peter            9875 20-JAN-11 Russia              1 Japan
    Peter            9870 15-JAN-11 Iran                1 Japan
    Peter            9878 26-JAN-11 Korea               0 Japan
    Peter            9854 13-JAN-11 Taiwan              0 Japan
    12 rows selected.

  • 11g: can connet using SQL*PLUS, not with TOAD

    Hi
    I run into a problem with TOAD. I can't connect with my 11g database using TOAD. I don't get any messages it just gives me a little waiticon for a split second and then nothing happens. I can however connect to my 10g database using TOAD. Using SQL*Plus I can connect to both.
    I use TOAD 8.6. Do I need a newer version maybe??...

    I can connect like:
    hr/pw@xe
    or
    hr/pw@O11R1
    or directly, no problem. I can connect from SQLplus to both databases any way I want

Maybe you are looking for

  • Pages 5.0.1 crashes constantly when formatting items

    I have Pages 5.0.1 installed from the app store on Mavericks on my Retina Macbook Pro. Literally everyother time I select a formatting style, the app will crash.  I have no idea what is going on.  I've uninstalled and reinstalled and still no luck. 

  • Aperture won't switch to old library

    I go to switch to my Aperture 1.5.6 library and it says that it needs to relaunch. But when it does so, I get a box asking if I want to create a new library which only gives me the option to create a new library or quit the program. I've tried creati

  • Print or Submit Depending on if PDF has digital signature

    hello everyone!! i have a quick question and please let me know if i am posting this in the wrong area. i have a pdf form created in Acrobat 7 but we need to reader rights enabled so I have since them downloaded acrobat pro 9 and revamped it.  it wor

  • Camera light on for no reason plus Virus?

    2 Questions this time. First, I've been having a lot of difficulty getting my battery to charge and stay charged. Finally I got it charging this evening, but when the computer turned on, the green camera light is also on. There are absolutely NO appl

  • "unable to connect to server/OK"

    I'm in iCloud ****. I keep getting an intrusive prompt stating "New iCloud Terms and Conditions -- To use iCloud on this iPhone you must accept the new Terms and Conditions." Underneath are options to "View Terms" or "Not Now." When I click on "View