473,376 Members | 1,043 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,376 software developers and data experts.

Help with date parameter and if/else statement

Hi,

I'm trying to run a select statement that takes includes an if/else
clause. I need to select the 'tran_date' between....

if the current month is greater than 10 i.e. after OCT then the
tran_date will be between '01-Oct' - plus current year or the
tran_date is '01-Oct' plus previous year.

and the current date

Here is my script so far:

SELECT a.resource_code ASSOCIATE, a.tran_date START_DATE,
b.description PROJECT_CODE, sysdate
FROM actrans a, acactivity b, dual c
WHERE a.resource_type = 'E'
AND a.acct_category = 'TIME'
and a.activity like '9-WW-357852%'
and b.activity = a.activity
and tran_date between

if to_char(sysdate, 'MM') > 10)
begin
a.tran_date = '01-Oct' & to_char(sysdate, 'YY')
end
else
begin
a.tran_date = '01-Oct' & to_char(sysdate, 'YY'- 1))
End
ORDER BY tran_date

Can anyone help me out with this? I need to run it as a job, but not
sure whether I should be using a stored procedure etc..

Thanks in advance.
George
Jul 20 '05 #1
1 1822

"George" <ge***********@eu.watsonwyatt.com> wrote in message
news:d4**************************@posting.google.c om...
Hi,

I'm trying to run a select statement that takes includes an if/else
clause. I need to select the 'tran_date' between....

if the current month is greater than 10 i.e. after OCT then the
tran_date will be between '01-Oct' - plus current year or the
tran_date is '01-Oct' plus previous year.

and the current date

Here is my script so far:

SELECT a.resource_code ASSOCIATE, a.tran_date START_DATE,
b.description PROJECT_CODE, sysdate
FROM actrans a, acactivity b, dual c
WHERE a.resource_type = 'E'
AND a.acct_category = 'TIME'
and a.activity like '9-WW-357852%'
and b.activity = a.activity
and tran_date between

if to_char(sysdate, 'MM') > 10)
begin
a.tran_date = '01-Oct' & to_char(sysdate, 'YY')
end
else
begin
a.tran_date = '01-Oct' & to_char(sysdate, 'YY'- 1))
End
ORDER BY tran_date

Can anyone help me out with this? I need to run it as a job, but not
sure whether I should be using a stored procedure etc..

Thanks in advance.
George


Your code appears to be Oracle SQL, not Microsoft SQL, so I'm not sure how
you would write the query, given that date functions are quite different
between the two (as far as I know). And you also say "between", but you only
mention one date value, not two - perhaps you mean "greater than"? In any
event, what you're looking for is the CASE statement - in TSQL, one way to
write the query might be something like this:

SELECT
a.resource_code ASSOCIATE,
a.tran_date START_DATE,
b.description PROJECT_CODE,
current_timestamp
FROM
actrans a
inner join acactivity b
on b.activity = a.activity
WHERE
a.resource_type = 'E'
AND a.acct_category = 'TIME'
and a.activity like '9-WW-357852%'
and tran_date >
case
when datepart(mm, current_timestamp) > 10
then cast(convert(char(4), current_timestamp, 112)+'1001' as datetime)
else cast(cast(datepart(yy, current_timestamp)-1 as char(4)) + '1001' as
datetime)
end

Assuming you are using Oracle, you should post this in an Oracle newsgroup
for a better answer.

Simon
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jill | last post by:
I am trying to store the current date to an ms access database on my server. I set it up with a dsnless connection. Here is the statement: Insert Into employees(timestamp) Values ('" & date() &...
9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
18
by: James Radke | last post by:
Hello, We are currently using a user DLL that when working in VB 6.0 has a user defined type as a parameter. Now we are trying to use the same DLL from a vb.net application and are having...
0
by: DhavalPatel1983 | last post by:
Hi, I need help in VB Datareport, my problem describe as below.... I have one Bank application project with all the information like Deposite,Clearness,Check,Cash,Creadit,ATM...
9
by: pic078 via AccessMonster.com | last post by:
I need serious help - I have a frontend/backend Access database (2 MDE Files) that remains stuck in task manager after exiting the application - you can't reopen database after exiting as a result...
2
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
7
by: gubbachchi | last post by:
Hi all, In my application I need to display the data fetched from mysql database after the user selects date from javascript calender. I have written the code in which after the user selects the...
0
by: Michael | last post by:
I know I am missing something simple, but I am stuck. When I submit the following for the employee info gets stored in scale1 and scale1 shows the employee number. Can someone show me my...
0
by: bgreer5050 | last post by:
I know I am missing something simple, but I am stuck. When I submit the following for the employee info gets stored in scale1 and scale1 shows the employee number. Can someone show me my...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.