Live Traffic Feed

A visitor from Yekaterinburg viewed 'Vimal Vataliya' 5 days 10 hrs ago
A visitor from Voronezh viewed 'filter row datagrid with multiple column on keyup ' 22 days 14 hrs ago
A visitor from St petersburg viewed 'Vimal Vataliya' 24 days 3 hrs ago
A visitor from Boardman viewed 'Vimal Vataliya' 24 days 3 hrs ago
A visitor from Virginia viewed 'Vimal Vataliya' 24 days 3 hrs ago
A visitor from Washington viewed 'filter row datagrid with multiple column on keyup ' 24 days 9 hrs ago
A visitor from Gatchina viewed 'filter row datagrid with multiple column on keyup ' 25 days 22 hrs ago
A visitor from Yekaterinburg viewed 'Open Source cryptocurrency Exchanges | Vimal Vatal' 27 days 17 hrs ago
A visitor from Gatchina viewed 'Open Source cryptocurrency Exchanges | Vimal Vatal' 1 month ago
A visitor from Omsk viewed 'Open Source cryptocurrency Exchanges | Vimal Vatal' 1 month 4 days ago

Friday, April 27, 2018

get data for candle chart as per specific interval from sql server

Leave a Comment
Query for get data as per specific interval
Assume tablename=UserOrders,column=Price,column for date=CreatedDate, column for confirm order=Status, column for delete row status=IsActive:

Query:

For @interval you can pass any int value.(for ex. for 1 day interval you can pass 1440)


DECLARE @interval INT
SELECT DATEADD(MINUTE,FLOOR(DATEDIFF(MINUTE,0,CreatedDate)/@interval)*@interval,0) [date],MAX(Price) high,Min(Price) as low,
       ISNULL((SELECT TOP 1 Price FROM UserOrders WHERE DATEADD(MINUTE,FLOOR(DATEDIFF(MINUTE,0,CreatedDate)/@interval)*@interval,0)=DATEADD(MINUTE,FLOOR(DATEDIFF(MINUTE,0,U.CreatedDate)/@interval)*@interval,0) AND Status=2 ORDER BY CreatedDate asc),0) [open],
       ISNULL((SELECT TOP 1 Price FROM UserOrders WHERE DATEADD(MINUTE,FLOOR(DATEDIFF(MINUTE,0,CreatedDate)/@interval)*@interval,0)=DATEADD(MINUTE,FLOOR(DATEDIFF(MINUTE,0,U.CreatedDate)/@interval)*@interval,0) AND Status=2 ORDER BY CreatedDate desc),0) [close]
       from UserOrders U where IsActive=1 AND Status=2 GROUP BY DATEADD(MINUTE,FLOOR(DATEDIFF(MINUTE,0,U.CreatedDate)/@interval)*@interval,0)


If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment