I have this SELECT
statement in SQL Server:
select testname as 'Test',
tests_morning ,
tests_evening ,
Date
from labtests_hajj
left join departments_statistics on departments_statistics.test_id = labtests_hajj.testid
inner join departments on labtests_hajj.dept_id = departments.dept_id
The output now like this:
Test tests_morning tests_evening Date
CBC null null null
CALCIUM null null null
SODIUMN null null null
How can I get the output as script and add the date also depends on date range for example I need the output for 3 days to be like this :
Test tests_morning tests_evening Date
CBC null null 01/06/2023
CALCIUM null null 01/06/2023
SODIUMN null null 01/06/2023
CBC null null 02/06/2023
CALCIUM null null 02/06/2023
SODIUMN null null 02/06/2023
CBC null null 03/06/2023
CALCIUM null null 03/06/2023
SODIUMN null null 03/06/2023
How can I do the select and put 2 dates and show the output like thie?
1条答案
按热度按时间7nbnzgx91#
There are have two ways
With DimDate
If your date range is consecutive, you can create the desired data by setting the start and end dates with CTE.