Click here to Skip to main content
15,921,716 members
Home / Discussions / Database
   

Database

 
QuestionNeed Query for getting MONTHNAME,YEAR from my DateColumn SQLSERVER Pin
kish2014-Jul-09 20:23
kish2014-Jul-09 20:23 
AnswerRe: Need Query for getting MONTHNAME,YEAR from my DateColumn SQLSERVER Pin
Blue_Boy14-Jul-09 21:28
Blue_Boy14-Jul-09 21:28 
AnswerRe: Need Query for getting MONTHNAME,YEAR from my DateColumn SQLSERVER Pin
infneeta15-Jul-09 23:27
infneeta15-Jul-09 23:27 
QuestionLinked SQL Servers problem Pin
goodideadave14-Jul-09 7:18
goodideadave14-Jul-09 7:18 
AnswerRe: Linked SQL Servers problem Pin
Mycroft Holmes14-Jul-09 19:32
professionalMycroft Holmes14-Jul-09 19:32 
GeneralRe: Linked SQL Servers problem Pin
goodideadave15-Jul-09 6:20
goodideadave15-Jul-09 6:20 
GeneralRe: Linked SQL Servers problem Pin
Mycroft Holmes15-Jul-09 12:31
professionalMycroft Holmes15-Jul-09 12:31 
QuestionAverage value after 3 time intervals. Pin
Robert Vrinceanu14-Jul-09 5:52
Robert Vrinceanu14-Jul-09 5:52 
I have a simple table with 3 fields: ID, Tag1, Data

ID      Tag1            Data
________________________________
1     2     6/1/2009 22:00
2     1     6/1/2009 23:00
3     2     6/2/2009 6:00
4     3     6/2/2009 7:00
5     2     6/2/2009 8:00
6     2     6/2/2009 9:00
7     2     6/2/2009 10:00
8     1     6/2/2009 11:00
9     2     6/2/2009 11:30
10     1     6/2/2009 13:00
11     2     6/2/2009 14:00
12     2     6/2/2009 15:00
13     2     6/2/2009 16:00
14     1     6/2/2009 17:00
15     2     6/2/2009 18:00
16     1     6/2/2009 19:00
17     1     6/2/2009 20:00
18     2     6/2/2009 21:00
19     2     6/2/2009 22:00
20     3     6/2/2009 23:00
21     1     6/2/2009 23:59
22     2     6/3/2009 1:00
23     3     6/3/2009 2:00
24     2     6/3/2009 3:00
25     3     6/3/2009 4:00
26     2     6/3/2009 5:00
27     3     6/3/2009 6:00
28     2     6/3/2009 7:00
29     3     6/3/2009 8:00
30     2     6/3/2009 9:00
31     3     6/3/2009 10:00
32     2     6/3/2009 11:00
33     1     6/3/2009 11:55
34     2     6/3/2009 22:00
35     2     6/3/2009 23:00

Must I do a average AVG(Tag1) after 3 hourly intervals over a period of time (3 tours).
Hourly intervals are:

10.30 PM - 6.30 AM,   (represents tour1)
06.30 AM - 14.30 PM, (represents tour2)
14.30 PM - 22.30 PM, (represents tour3)

I tried this:

SELECT     
        AVG(CASE WHEN DATEPART(hour, DataTime) BETWEEN DATEPART(hour,'10:30:00 PM')   AND DATEPART(hour,'06:30:00 AM')   THEN Tag1 ELSE NULL END) AS tour1,
        AVG(CASE WHEN DATEPART(hour, DataTime) BETWEEN DATEPART(hour,'6:30:00 AM')   AND DATEPART(hour,'2:30:00 PM')   THEN Tag1 ELSE NULL END) AS tour2,
           AVG(CASE WHEN DATEPART(hour, DataTime) BETWEEN DATEPART(hour,'2:30:00 PM')   AND DATEPART(hour,'10:30:00 PM') THEN Tag1 ELSE NULL END) AS tour3
FROM         dbo.TableTest
WHERE         (DataTime BETWEEN '6/1/2009 10:00:00 PM' AND '6/3/2009 11:00:00 PM')
GROUP BY DATEPART(DAY,DataTime)

The result looks like:


tour1         tour2                     tour3
__________________________________________________________
NULL           NULL                 1.0
NULL           2.2222222222222223     1.7777777777777777
NULL           1.7142857142857142     2.0

Note:
For tour1 and tour2, belonging on the same day, is well calculated. The problem is tour1 - time which belongs to two days.
Can help me someone in this problem?
Thanks.

Regards,
Robert
AnswerRe: Average value after 3 time intervals. Pin
Luc Pattyn14-Jul-09 6:22
sitebuilderLuc Pattyn14-Jul-09 6:22 
GeneralRe: Average value after 3 time intervals. Pin
Robert Vrinceanu14-Jul-09 8:52
Robert Vrinceanu14-Jul-09 8:52 
QuestionSetting up User Accounts. Pin
Droze14-Jul-09 5:35
Droze14-Jul-09 5:35 
AnswerRe: Setting up User Accounts. Pin
DoctorMick14-Jul-09 6:23
DoctorMick14-Jul-09 6:23 
GeneralRe: Setting up User Accounts. Pin
Droze14-Jul-09 7:14
Droze14-Jul-09 7:14 
AnswerRe: Setting up User Accounts. Pin
ScottM115-Jul-09 2:43
ScottM115-Jul-09 2:43 
QuestionAS 400 System tables Pin
Ersan Ercek14-Jul-09 0:28
Ersan Ercek14-Jul-09 0:28 
AnswerRe: AS 400 System tables Pin
David Skelly14-Jul-09 6:19
David Skelly14-Jul-09 6:19 
AnswerRe: AS 400 System tables Pin
Giorgi Dalakishvili14-Jul-09 6:21
mentorGiorgi Dalakishvili14-Jul-09 6:21 
Questionhow to know current date and time Pin
janani1313-Jul-09 21:37
janani1313-Jul-09 21:37 
AnswerRe: how to know current date and time Pin
Eddy Vluggen13-Jul-09 22:31
professionalEddy Vluggen13-Jul-09 22:31 
GeneralRe: how to know current date and time Pin
janani1313-Jul-09 23:26
janani1313-Jul-09 23:26 
AnswerRe: how to know current date and time Pin
Md. Marufuzzaman14-Jul-09 19:18
professionalMd. Marufuzzaman14-Jul-09 19:18 
GeneralRe: how to know current date and time Pin
ScottM115-Jul-09 2:47
ScottM115-Jul-09 2:47 
Questiondisplay exactly 2 digits after decimal point in money Pin
janani1313-Jul-09 18:59
janani1313-Jul-09 18:59 
AnswerRe: display exactly 2 digits after decimal point in money Pin
_Damian S_13-Jul-09 19:27
professional_Damian S_13-Jul-09 19:27 
AnswerRe: display exactly 2 digits after decimal point in money Pin
goodideadave14-Jul-09 7:24
goodideadave14-Jul-09 7:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.