Tags

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,


T-SQL Query | [ Normalize (Divide) Amount between Months ]  – In this puzzle we have Normalize (Divide) Amount between Months. Please check out the sample input and expected output for details.

Sample Input

Start End Amount
14-Apr-14 13-May-14 200
15-May-14 16-Jun-14 320

Expected Output

Start End Amount
14-Apr-14 30-Apr-14 100
01-May-14 13-May-14 100
15-May-14 31-May-14 160
01-Jun-14 16-Jun-14 160

Rules/Restrictions

  • The solution should be should use “SELECT” statement or “CTE”.
  • Add your solution(s) in the comments section or send you solution(s) to pawankkmr@gmail.com

Script

Use the below script to generate the source table and fill them up with the sample data.


--Create Table

CREATE TABLE TestSplitData
(
 Start DATETIME
,EndDt DATETIME
,Amount INT
)
GO

--Insert Data

INSERT INTO TestSplitData(Start,EndDt,Amount)
VALUES
('14-Apr-14','13-May-14',200),
('15-May-14','16-Jun-14',320)

--Verify Data

SELECT Start,EndDt,Amount FROM TestSplitData

Please leave a comment if you need solution to the above puzzle

Keep Learning

Advertisements