Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Goodday! I have this form where the user/encoder can select agency and its project, and a combobox which he has to select if First, Second, Third, Fourth Quarter of the year. When First is selected, all transactions of that agency should be listed from January to March.

SQL
SELECT ctrl_no, a_code, prj_code
FROM tbltrans
where date_created >=('1 January 2012')
and date_created <= ('31 March 2012')


Thanks!
Posted
Comments
André Kraak 25-Nov-12 14:19pm    
Please specify the properties of the date_created field.
Is it a text field?
Jörgen Andersson 25-Nov-12 15:08pm    
And please specify the database used.
Member 9372112 25-Nov-12 15:42pm    
I am using ORACLE 10g xe

Before you can do anything you need to convert the text to a date using TO_DATE[^].
With the date you can use TO_CHAR[^] to get the quarter in which the date belongs.
Both functions use Datetime Format Elements[^].
SQL
SELECT ctrl_no, a_code, prj_code
FROM tbltrans
WHERE TO_CHAR( TO_DATE( date_created, 'DD Month YYYY', 'nls_date_language = us' ), 'Q') = '1'
 
Share this answer
 
v3
Comments
Member 9372112 25-Nov-12 15:40pm    
Thanks for your reply.
But i stored it as varchar.
André Kraak 25-Nov-12 16:26pm    
I altered the solution for your situation.
Member 9372112 25-Nov-12 22:40pm    
Hi sir. I tried this but im getting this error :
ORA-12702: invalid NLS parameter string used in SQL function
Sorry to bother you.
André Kraak 26-Nov-12 3:19am    
I made a error in specifying the NLS parameter, how it is used is defined here http://docs.oracle.com/cd/B14117_01/server.101/b10749/ch9sql.htm#sthref1105[^].

I corrected the answer.
Member 9372112 30-Nov-12 20:05pm    
I have figured out this one. What i input is 1, 2, 3 or 4. What i want to see is the transactions covered from that quarter. For example, i input 4, all records dated november showed but january is also included. i want to exclude that.
use DatePart function. See here[^]
 
Share this answer
 
Comments
André Kraak 26-Nov-12 3:34am    
Unfortunately DatePart is not available in ORACLE 10g, the database the OP is using (as specified in the comments).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900