Tuesday, January 28, 2014

Split date range without Calendar table

Try using a temporary table rather than table variable.. You can have a CI on the date column.


or



declare @PeriodStart datetime2(0) = '2013-01-05 00:00:00'
declare @PeriodEnd datetime2(0) = '2013-01-05 02:00:00'



select T.PeriodStart, T.PeriodEnd, count(Column1)as count1, sum(Column2)as sum1
from Fact F with(nolock)WHERE F .[Start]>= '19000101' AND <=@PeriodStart
and F.[End] >= @PeriodEnd and F.[End] <='20200101'


group by T.PeriodStart, T.PeriodEnd



Best Regards,Uri Dimant SQL Server MVP, http://ift.tt/1iQ9JkR



MS SQL optimization: MS SQL Development and Optimization

MS SQL Consulting: Large scale of database and data cleansing

Remote DBA Services: Improves MS SQL Database Performance

SQL Server Integration Services: Business Intelligence


No comments:

Post a Comment