Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another question

Status
Not open for further replies.

Altamarus

Programmer
Jan 25, 2006
16
CA
It's similar to my other post...

I have a table like this

//STARTING_DATE//DAY1//DAY2//DAY3//DAY4...//DAY7
////////////////////////////////////////////////
//2005-01-02 // 0 // 16 // ...
//2005-01-09 // 0 // 18 // ...
//2005-01-16 // 0 // 18 // ...
//2005-01-23 // 0 // 18 // ...
//2005-01-30 // 0 // 16 // ...
/////////////////////////////////////////////////
Where day 1 to day 7 are the days worked (DAY>0) or not(0) worked in the week for the month. I just cannot figure out how I could count the number of days worked in the month depending on the date entered by the user.


Thank you =D
 
I tried your last in query analyser and it gives me

Dates///////Days
2006-12-31//15

Since 01/01/2007 is a non-worked day, the result should be 0


Sorry for the delay I was working on another project
 
I dont now if this can help, but my date format is yyyy-mm-dd
 
Since 01/01/2007 is a non-worked day, the result should be 0

Unless you have entries for the week of 12/31/2006 Through 1/6/2007.

Try replacing 1/1/2007 with a different value. The query will take the date entered and figure out all hours worked within the work week of the date specified.
 
Let's say I enter 12-01-2006 (january 12th)

In my calendar table the entry is

2006-01-08(january 8th) 0 // 16 // 16 // 16 // 16 // 16 // 0

Where the week starts with Sunday and ends with saturday.

The resulting table is

Dates // Column name
2006-11-26 00:00:00.000 // 25

I think months and days are reversed in your code.
 
I forgot to switch this back after I was testing. Change your final Select Statement from

Code:
Select  Dates, Count(*) From #Temp Where Days > 0 Group By Dates

To

Code:
Select  Dates, Sum(Days) From #Temp Where Days > 0 Group By Dates
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top