SlideShare une entreprise Scribd logo
1  sur  1
--------------------------------------------------------------------------------
------------
DECLARE @startdate DATETIME
DECLARE @enddate DATETIME
DECLARE @id INT
DECLARE @totalcount INT
DECLARE @StartCounter INT = 1
DECLARE @BillDetailNormalized TABLE
(
ID INT,
StartDate DATETIME,
EndDate DATETIME
)
SELECT @totalcount = MAX(BillDetailID) from TempBillDetail
SET @StartCounter = 1
WHILE (@StartCounter <=@totalcount) --Total Records Loop
BEGIN
SELECT @startdate = StartDate,@enddate = EndDate FROM TempBillDetail WHERE
BillDetailID= @StartCounter
WHILE (DATEPART(MM,@startdate) <= DATEPART(MM,@enddate))-- Start Date and
EndDate Loop
BEGIN
IF (DATEPART(MM,@startdate) = DATEPART(MM,@enddate))
INSERT INTO @BillDetailNormalized VALUES (@StartCounter, @startdate,@enddate)
ELSE IF (DATEPART(MM,@startdate) < DATEPART(MM,@enddate))
INSERT INTO @BillDetailNormalized VALUES (@StartCounter,
@startdate,EOMONTH(@STARTDATE))
SET @startdate = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@startdate)+1,0)) +1
END
SET @StartCounter = @StartCounter + 1
END
--------------------------------------------------------------------------------
---------------
DECLARE @ServiceBeginKey DATE= '2013-11-01'
DECLARE @ServiceEndKey DATE = '2014-10-31'
SELECT * from ClientFiscalPeriods c WHERE ClientKey = 9
AND (C.FiscalPeriodCalendarEndDateKey >= @ServiceBeginKey)
AND (C.FiscalPeriodCalendarBeginDateKey <= @ServiceEndKey)
--------------------------------------------------------------------------------
---------------

Contenu connexe

Similaire à Df

Metadata Matters
Metadata MattersMetadata Matters
Metadata Matters
afa reg
 
T sql denali code Day of .Net
T sql denali code Day of .NetT sql denali code Day of .Net
T sql denali code Day of .Net
KathiK58
 
Seistech SQL code
Seistech SQL codeSeistech SQL code
Seistech SQL code
Simon Hoyle
 
Paging storedprocedure
Paging storedprocedurePaging storedprocedure
Paging storedprocedure
seethalux
 
Organic Gardens SQL Database Schema By Christopher Kaczor
Organic Gardens SQL Database Schema By Christopher KaczorOrganic Gardens SQL Database Schema By Christopher Kaczor
Organic Gardens SQL Database Schema By Christopher Kaczor
Christopher Kaczor
 
Mdp plus 2.1
Mdp plus 2.1Mdp plus 2.1
Mdp plus 2.1
boedax
 
[INSIGHT OUT 2011] B24 effective indexing(tom kyte)
[INSIGHT OUT 2011] B24 effective indexing(tom kyte)[INSIGHT OUT 2011] B24 effective indexing(tom kyte)
[INSIGHT OUT 2011] B24 effective indexing(tom kyte)
Insight Technology, Inc.
 
Set Focus SQL Portfolio
Set Focus SQL PortfolioSet Focus SQL Portfolio
Set Focus SQL Portfolio
brentbybee
 

Similaire à Df (20)

Add invoice
Add invoiceAdd invoice
Add invoice
 
SAV
SAVSAV
SAV
 
Metadata Matters
Metadata MattersMetadata Matters
Metadata Matters
 
How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012
 
T sql denali code Day of .Net
T sql denali code Day of .NetT sql denali code Day of .Net
T sql denali code Day of .Net
 
Seistech SQL code
Seistech SQL codeSeistech SQL code
Seistech SQL code
 
MK1_Addendum
MK1_AddendumMK1_Addendum
MK1_Addendum
 
MariaDB Temporal Tables
MariaDB Temporal TablesMariaDB Temporal Tables
MariaDB Temporal Tables
 
as400 built in function- %MINUTES
as400 built in function- %MINUTESas400 built in function- %MINUTES
as400 built in function- %MINUTES
 
as400 built in function- %SECONDS
as400 built in function- %SECONDSas400 built in function- %SECONDS
as400 built in function- %SECONDS
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
 
Paging storedprocedure
Paging storedprocedurePaging storedprocedure
Paging storedprocedure
 
Organic Gardens SQL Database Schema By Christopher Kaczor
Organic Gardens SQL Database Schema By Christopher KaczorOrganic Gardens SQL Database Schema By Christopher Kaczor
Organic Gardens SQL Database Schema By Christopher Kaczor
 
as400 built in function- %HOURS
as400 built in function- %HOURSas400 built in function- %HOURS
as400 built in function- %HOURS
 
Mdp plus 2.1
Mdp plus 2.1Mdp plus 2.1
Mdp plus 2.1
 
[INSIGHT OUT 2011] B24 effective indexing(tom kyte)
[INSIGHT OUT 2011] B24 effective indexing(tom kyte)[INSIGHT OUT 2011] B24 effective indexing(tom kyte)
[INSIGHT OUT 2011] B24 effective indexing(tom kyte)
 
JKJ_T SQL project code samples
JKJ_T SQL project code samplesJKJ_T SQL project code samples
JKJ_T SQL project code samples
 
Writeable CTEs: The Next Big Thing
Writeable CTEs: The Next Big ThingWriteable CTEs: The Next Big Thing
Writeable CTEs: The Next Big Thing
 
Set Focus SQL Portfolio
Set Focus SQL PortfolioSet Focus SQL Portfolio
Set Focus SQL Portfolio
 
Loopback.vhd
Loopback.vhdLoopback.vhd
Loopback.vhd
 

Df

  • 1. -------------------------------------------------------------------------------- ------------ DECLARE @startdate DATETIME DECLARE @enddate DATETIME DECLARE @id INT DECLARE @totalcount INT DECLARE @StartCounter INT = 1 DECLARE @BillDetailNormalized TABLE ( ID INT, StartDate DATETIME, EndDate DATETIME ) SELECT @totalcount = MAX(BillDetailID) from TempBillDetail SET @StartCounter = 1 WHILE (@StartCounter <=@totalcount) --Total Records Loop BEGIN SELECT @startdate = StartDate,@enddate = EndDate FROM TempBillDetail WHERE BillDetailID= @StartCounter WHILE (DATEPART(MM,@startdate) <= DATEPART(MM,@enddate))-- Start Date and EndDate Loop BEGIN IF (DATEPART(MM,@startdate) = DATEPART(MM,@enddate)) INSERT INTO @BillDetailNormalized VALUES (@StartCounter, @startdate,@enddate) ELSE IF (DATEPART(MM,@startdate) < DATEPART(MM,@enddate)) INSERT INTO @BillDetailNormalized VALUES (@StartCounter, @startdate,EOMONTH(@STARTDATE)) SET @startdate = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@startdate)+1,0)) +1 END SET @StartCounter = @StartCounter + 1 END -------------------------------------------------------------------------------- --------------- DECLARE @ServiceBeginKey DATE= '2013-11-01' DECLARE @ServiceEndKey DATE = '2014-10-31' SELECT * from ClientFiscalPeriods c WHERE ClientKey = 9 AND (C.FiscalPeriodCalendarEndDateKey >= @ServiceBeginKey) AND (C.FiscalPeriodCalendarBeginDateKey <= @ServiceEndKey) -------------------------------------------------------------------------------- ---------------