Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Missing Hours
Message
 
To
02/03/2019 04:11:44
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows 10
Network:
Windows Server 2008 R2
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01666883
Message ID:
01666884
Views:
55
>Sir while using SQLSERVER 2012, I have these codes
>
>
>
>SELECT hrs,Max(reading)as reading
>FROM   bin1
>WHERE (CONVERT(VARCHAR(10), date, 103) = CONVERT(VARCHAR(10), GETDATE(), 103))
> AND (hrs IS NOT NULL) and updown=0 and tik is null
>group by hrs
>union
>SELECT hrs,max(reading)as reading
>FROM   bin1_empty
>WHERE (CONVERT(VARCHAR(10), date, 103) = CONVERT(VARCHAR(10), GETDATE(), 103))
> AND (hrs IS NOT NULL)
>group by hrs
>order by hrs
>
>
>It display following result
>
>
>But I want to get this result
>
>
>Hours from 0 to 23
>Missed hours must have value 0
>
>Please
;with cte_hours(Hours)
AS
(
   SELECT 0 AS Hours
   UNION ALL
   SELECT Hours+1 as Hours
   FROM cte_hours
   WHERE Hours < 23
)

select ISNULL(Data.hrs, cte.Hours)  AS Hrs
      ,MAX(ISNULL(data.reading, 0)) AS reading
from (SELECT hrs
            ,Max(reading)as reading
      FROM   bin1
      WHERE CONVERT(date, date) = CONVERT(date, GETDATE())
        AND hrs IS NOT NULL
        AND updown=0
        AND tik is null
	  group by hrs
      UNION
	  SELECT hrs,max(reading)as reading
      FROM   bin1_empty
      WHERE CONVERT(date, date) = CONVERT(date, GETDATE())
		AND hrs IS NOT NULL
	  group by hrs) as data
CROSS JOIN cte_hours cte
group by 1
order by 1
NOT TESTED!
:-)
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform