Sample Header Ad - 728x90

Add default rows to the query result if restrictions are not met

11 votes
3 answers
3926 views
I have a SQL query that looks for values in a table on a range of dates. If no record is found, I would like to generate rows with default values. Example of one of the table existing records: DeviceId| Time | Context |Value --------|----------|---------|----- 1 |2022-02-10|Connected|False So a query that restricts on the Time column between 2022-02-07 and 2022-02-10 must create fake rows for February 7th, 8th, and 9th but not for the 10th because that already exists. Expected result: DeviceId| Time | Context |Value --------|----------|---------|----- 1 |2022-02-7 |Fake |False 1 |2022-02-8 |Fake |False 1 |2022-02-9 |Fake |False 1 |2022-02-10|Connected|False How can I do that? With a recursive CTE?
Asked by anon
Feb 10, 2022, 01:12 PM
Last activity: Feb 11, 2022, 03:24 AM