1. Olan Knight
  2. PowerBuilder
  3. Tuesday, 4 January 2022 16:04 PM UTC

PB2019R3, build 2703
Windows 10, 64 bit platform
PostgreSQL database connected with ODBC


I have a stand-alone datawindow which is a report. The full SQL is attached.

Here's a snippet of the problem lines in the SQL:
            select
            case
            when to_number(to_char(:thru_bill_date,'MM')) - pd_ctr.pd_back <= 0 then
                    to_number(to_char(:thru_bill_date,'YYYY')) - 1
            else to_number(to_char(:thru_bill_date,'YYYY'))
            end ||'-'||
            case

1) When I replace the parameter ":thru_bill_date" with TO_DATE ('11/05/2021,'MM/DD/YYYY') in an Oracle or a PG database, then it works. 
    However, I need the parameter as that value changes each month.

2) When I run this SQL with these lines in an Oracle database, it works.
    When I run this SQL with these lines in a PG database, I get this:



3) When I replace the parameter ":thru_bill_date" with  "TO_DATE (:thru_bill_date, 'MM/DD/YYYY')" in an Oracle database, I get this error:


When I replace the parameter ":thru_bill_date" with  "TO_DATE (:thru_bill_date, 'MM/DD/YYYY')" in a PG database, I get this error:



4) When I replace the parameter ":thru_bill_date" with "TRUNC ( :thru_bill_date )" in an Oracle database, it works.
    When I replace the parameter ":thru_bill_date" with "TRUNC ( :thru_bill_date )" in a PG database, I get this error:

 

Any ideas on how to get this to work? Or perhaps a work-around?


Thank You,

Olan

Attachments (1)
René Ullrich Accepted Answer Pending Moderation
  1. Wednesday, 5 January 2022 06:36 AM UTC
  2. PowerBuilder
  3. # 1

Hi Olan,

If you use SQL trace you will see that PB codes the date as string in the sql. So the database gets a command "to_char(string, string)" that it can't understand.

Change your code to:  to_char (date :t_billhru_date, 'MM/DD/YYYY')

It tells the database that the string is a date.

 

BTW: Instead of conversion to string and number to extract the month or year you could also use the "extract" function: extract(month from date :t_billhru_date)

 

Regeards,

René

Comment
  1. Olan Knight
  2. Sunday, 9 January 2022 23:08 PM UTC
Thank you, Rene, I will try that next week!

  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.