SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Collect data on the basis of timestamp from a table in a view


Collect data on the basis of timestamp from a table in a view

Author
Message
nidhi.finance1
nidhi.finance1
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 13
Hi,
I am having data in a table in the form


L_Limit    U_Limit       Asset      Timestamp
10 20 1000 2013-06-14 16:52:57.910
20 30 1500 2013-06-14 16:52:57.910
30 40 2200 2013-06-14 16:52:57.910
10 20 2000 2013-06-15 18:52:57.910
20 30 1300 2013-06-15 18:52:57.910
30 40 2100 2013-06-15 18:52:57.910
10 20 3000 2013-06-16 18:20:27.910
20 30 2300 2013-06-16 18:20:27.910
30 40 1100 2013-06-16 18:20:27.910


i.e. a Job appends data(i.e. value of asset) for same ranges 10 to 20,20 to 30 and 30 to 40 everyday when I run a job schedule. This data will be stored on a daily basis for months.

Also, this limit range is also saved separately in 'Range' table as columns:

Lower_Limit   Upper_Limit
10 20
20 30
30 40




My requirement is to show this data in this format in a view to show asset value on 3 days i.e. Today, before 7 days, before 30 days:


L_Limit  U_Limit  Asset_Today   Asset_Before7Days  Asset_Before30Days
10 20
20 30
30 40



Please suggest how can I get data in this format?
Thanks in advance.
J Livingston SQL
J Livingston SQL
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12265 Visits: 37557
nidhi.finance1 (6/16/2013)


My requirement is to show this data in this format in a view to show asset value on 3 days i.e. Today, before 7 days, before 30 days:


L_Limit  U_Limit  Asset_Today   Asset_Before7Days  Asset_Before30Days
10 20
20 30
30 40



Please suggest how can I get data in this format?
Thanks in advance.


based on what you have posted so far....what results are you expecting to return from your data?

________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day

Kingston Dhasian
Kingston Dhasian
SSCertifiable
SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)

Group: General Forum Members
Points: 6044 Visits: 5280
Something like this..
SELECT L_Limit,
U_Limit,
SUM(CASE
WHEN DATEDIFF(day, Timestamp, CURRENT_TIMESTAMP) = 0 THEN Asset
ELSE 0
END) AS Asset_Today,
SUM(CASE
WHEN DATEDIFF(day, Timestamp, CURRENT_TIMESTAMP) = 7 THEN Asset
ELSE 0
END) AS Asset_Before7Days,
SUM(CASE
WHEN DATEDIFF(day, Timestamp, CURRENT_TIMESTAMP) = 30 THEN Asset
ELSE 0
END) AS Asset_Before30Days
FROM YourTableName -- Replace with you table name
WHERE DATEDIFF(day, Timestamp, CURRENT_TIMESTAMP) IN ( 0, 7, 30 )
GROUP BY L_Limit,
U_Limit




Kingston Dhasian

How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search