473,506 Members | 9,749 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Doubt

1 New Member
Doubt to write a SQL:

I am having a table,with different fields such as date,week_end ,month_end,year_end etc
depends on the date I need to update the flags of the reamaining fields
eg: if date is 30/12/2010
week_end(last working day of the week) ='Y'
month_end(last working day of month) ='Y'
year_end (last working day of year) ='Y'

This date always varies and depends on this date I need to set the flags to the remaining fields
As I know only the basics of DB2,please anyone give me the complete SQL for the above mentioned scenario


Thanks in advance
Kimmy
Nov 18 '08 #1
1 2004
cburnett
57 New Member
Not sure if this is best way of doing it, but if your objective is to create a calendar table, the following might be what you are after:
Expand|Select|Wrap|Line Numbers
  1. create table days(dt date,
  2. week_end char(1) generated as 
  3.     (case dayofweek(dt)
  4.           when 6 then 'Y'
  5.           else            'N'
  6.      end),
  7. month_end char(1) generated as
  8.    (case
  9.          when month(dt) = month(date(dt) +
  10.                       (case dayofweek(date(dt))
  11.                             when 6 then 3
  12.                             when 7 then 0
  13.                             when 1 then 0
  14.                             else            1
  15.                        end) days) then 'N'
  16.           else                              'Y'
  17.     end),
  18. year_end char(1) generated as
  19.     (case
  20.           when year(dt) = year(date(dt) +
  21.                       (case dayofweek(date(dt))
  22.                             when 6 then 3
  23.                             when 7 then 0
  24.                             when 1 then 0
  25.                             else            1
  26.                        end) days) then 'N'
  27.            else                             'Y'
  28.      end)) 
Populate it with test data as follows and see if it's what you are after:
Expand|Select|Wrap|Line Numbers
  1. insert into days(dt)
  2.   with i(lvl) as 
  3.         (values(1)),
  4.          n(lvl) as (select lvl
  5.                         from i
  6.                       union all
  7.                       select n.lvl+1
  8.                         from n
  9.                       where n.lvl < 800)
  10.   select current date + lvl days from n
Nov 20 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1986
by: Guilherme Pinto | last post by:
Hello. I am reading the book written by Bjarne Stroustrup called " The C++ Programming Language - Special Edition" and had a doubt which a think is really important to distinguish between the...
138
5104
by: ambika | last post by:
Hello, Am not very good with pointers in C,but I have a small doubt about the way these pointers work.. We all know that in an array say x,x is gonna point to the first element in that...
4
2680
by: dam_fool_2003 | last post by:
I am just a beginner in tree data – struct. I have this little doubt. Left node ‘weights' lesser than the right one. I have seen, so far it is algorithm implementations. But why not vice-versa that...
20
1626
by: maadhuu | last post by:
firstly, i am thankful to all those who answered the 1st set of doubts. And i am not yet enlightened to that extent , coz ' i keep getting doubts. is the following defined in the language ?? int...
3
1320
by: SMG | last post by:
Hi All, It might be a silly doubt, but it is a doubt.... I am using form authentication for my website, now my web application is gonna be deployed on two web servers with Load Balancing...
77
3614
by: muttaa | last post by:
Hello all, My doubt is going to be so primitive that i ask you all to forgive me beforehand.... Here's the code snippet: int main() { int x=5;
11
2084
by: Bob Nelson | last post by:
I don't remember seeing the term ``doubt'' used much in c.l.c. back in the 90's. When did this word become nearly synonymous with ``question'' or ``query'' and does it have static duration?
122
4159
by: ivan | last post by:
hi all, if I have: if(A && B || C) which operation gets executed first? If I remeber well should be &&, am I correct? thanks
5
1700
by: Paulo | last post by:
Hi, I have a RadioButtonList and I need to do some verifications on a "OnChange" event on client... because on classic asp/html I just add a "onChange" event on <input type="radio" onChange="">,...
0
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5037
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1534
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.