Solved

How can I format my date properly inthis query?

Posted on 2009-03-31
2
229 Views
Last Modified: 2013-12-19
Hi There,

I ahve the below query with 3 parameters. How can I properly format the dates? Right now i get the error ORA-01841: (full) year must be between -4713 and +9999, and not be 0?

Thanks,
Rhonda
SELECT     primary_mobile_id AS Primary_Mobile_Num, NVL(b.description, 'Not-rated') AS billable, mobile_id AS Originator, 

                      cntry_num || called_num AS Destination, orig_zone AS Ocean_Region, to_char(call_dt, 'DD/MM/YYYY HH24:MI:SS') AS call_dt, call_dt AS call_date, 

                      customer_code AS CustCode, NVL(SUM(minutes), 0.00) AS Units, NVL(b_uom, 'mins') AS UOM, acct_period AS AcctPeriod, SUM(NVL(total_charge, 0)) 

                      AS Charges, rate_currency AS Currency

FROM         cdr_customer c, billable b

WHERE     primary_mobile_id = :MOBILE1 AND call_dt BETWEEN to_date(':SDATE1' || ' 00:00:00', 'YYYY-MM-DD HH24:MI:SS')  AND to_date(':EDATE1' || ' 23:59:59', 'YYYY-MM-DD HH24:MI:SS') AND c.billable = b.billable (+) AND rev_num >= 0

GROUP BY primary_mobile_id, mobile_id, cntry_num || called_num, orig_zone, to_char(call_dt, 'DD/MM/YYYY HH24:MI:SS'), call_dt, customer_code, 

                      NVL(b_uom, 'mins'), acct_period, invoice_num, rate_currency, NVL(b.description, 'Not-rated')

UNION

SELECT     imn_number AS Primary_Mobile_Num, NVL(b.description, 'Not-rated') AS billable, from_user AS Originator, to_user AS Destination, NVL(from_site, 

                      to_site) AS Ocean_Region, to_char(date_sent, 'DD/MM/YYYY HH24:MI:SS') AS call_dt, date_sent AS call_date, customer_code AS CustCode, 

                      NVL(SUM(billable_units), 0.00) AS Units, billable_uom AS UOM, acct_year AS AcctPeriod, SUM(NVL(space_charge, 0) + NVL(landline_charge, 0) 

                      + NVL(p_ndn_charge, 0)) AS Charges, rate_currency AS Currency

FROM         c_msgs c, billable b

WHERE     imn_number = :MOBILE1 AND date_sent BETWEEN :SDATE1 AND :EDATE1 AND c.billable = b.billable (+) AND rev_num >= 0

GROUP BY imn_number, from_user, to_user, NVL(from_site, to_site), to_char(date_sent, 'DD/MM/YYYY HH24:MI:SS'), date_sent, customer_code, billable_uom, 

                      acct_year, rate_currency, NVL(b.description, 'Not-rated')

ORDER BY 7

Open in new window

0
Comment
Question by:Rhonda Carroll
  • 2
2 Comments
 
LVL 73

Expert Comment

by:sdstuber
ID: 24028264
are :sdate1 and :edate1  dates or are they strings?

in one query you convert them to dates

  AND call_dt BETWEEN TO_DATE(':SDATE1' || ' 00:00:00', 'YYYY-MM-DD HH24:MI:SS')
                     AND  TO_DATE(':EDATE1' || ' 23:59:59', 'YYYY-MM-DD HH24:MI:SS')

but in the other you don't

AND date_sent BETWEEN :sdate1 AND :edate1


are call_dt and date_sent both dates?
0
 
LVL 73

Accepted Solution

by:
sdstuber earned 250 total points
ID: 24028282
in either case you don't want to put the binds inside the quotes

':SDATE1'  ':EDATE1'

if they are dates you don't want to convert them at all
if they are strings you should convert them the same in both cases

BETWEEN TO_DATE(:SDATE1 || ' 00:00:00', 'YYYY-MM-DD HH24:MI:SS')
                     AND  TO_DATE(:EDATE1 || ' 23:59:59', 'YYYY-MM-DD HH24:MI:SS')
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

1 Experts available now in Live!

Get 1:1 Help Now