Scripting/logic help

  • My head is well and truly mashed and I could do with some help please...
    I need to write a script to count the number of records opened and closed in certain dates.  This will require a pivot eventually but essentially we're looking at two tables - one has the open date, the other the closed date.  Both have a matching id.  So far so good.  Where I'm struggling is that I need to do a monthly breakdown that needs to be dynamic and increase each month to show the number of records closed in a given month number for a given month.   I'm having difficulty even explaining it let alone coding it!

    Example: 
    10 cases are opened in January
    12 in Feb
    3 in March

    Of the 10 opened in January, 2 are closed in January (Month 1), 3 are closed in February (Month 2) and 5 are closed in March (Month 3)
    Of the 12 opened in February, 7 are closed in February (Month 1), 1 in March (Month 2)
    Of the 3 opened in March, 1 is closed in March (Month 1)

    This would therefore be reflected something like:
    data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWIAAABKCAYAAACB1F6VAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAA3GSURBVHhe7Z0NuqosEMc573Kk5Ry7y4mWU57lpNvpnQFUJDS1TKD/7z4995gfNIDDMOjMz+12u0spBZhHXdcC9RUfubYL5MoTX/4f+tzNnwAAAD7F/d6rXihiAADYgdvtZv+yitjVzGCcnx+uruFIBvYn13aBXHkSkv8/+z8AAICdgCIGAICdGSri+iwOZDb//BxFZb/qqcRxdN8L6DLffM1PYevrcK7tF5ZNZKrF+fAjjltVVNf27Se2NuH+dxB+VQdJqR8vOS8FubrfaD6z+msKclXHTqafuf1wAQGLWAopK1H5v5C+qCTts5urWVoBCVCrc9rycCc7KFFc79pvpT9XMV/xRUkK/ZiUDNX7siqOWS4jT9ePriV1rbl9KGK5+NxjI9StlasQ6vBeHRZQxIUoSymaZlh7FVVIWZZ2C/SUQqlGnJPVWGRpn6lt6eah+6anvIqbEkL9Oy9UFLEQdz+uzwdt5TX0W5YpmYjl0kpTiVP7M8qTULIWdWO3J4lYLnkSt/tNnNqGot9TikZ4P/Ulgj7i4pcEr/6cG5BHKir812626FEmYK7b0eesO5vZb6bvrQXA0w1vpHRM/82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mUAACmTtiLWPmqaXiBzBwAgYdhGxjwbAAA+jOuagCIGAIAdQIaOlWCxLk6wqJUWWKx7lD+LxToAAEgZKGIAANiZoSK2TyGEY0i0D0M/e9NtIbrMFdf0z9srK8OgXAR+j4L2aRq/Mdw+M9bv5hzDTO3bCl0m5Bow5xhmal8EBCxiKaT7GnMLx3OQtM9u7gsNCn6Ggj2yMnDjHhuh2rgY10KoQ7yN/W3kmvEBcuVHQBEXoiylaLzoGhzhbCzO7yeZl6GAFLWOabxxnAfJQbqdgD76pZJAYBKwA7lmfIBcORL0ERe/pL6qv0FwjaoiJfNrN1tmZtLQ3+qpQX/sQ8wF51qT8Ri2yLLxJky5rwQeAu8k14wPkCs/wot1HGWNqqML+M5uiYdXiFur03EFjGTS4GsNEmnelGgGUdVoPyn69jpTEde2yLLxMnaQ0XGOLgj+Hg+5ZnyAXLkRVsRUIcYoNlo17JZYkElD+5cdC1VP6V23gRSq3Vm86IfeIyuDlocHEfiIoyPXjA+QKytGFDHpls49Yd0SIcU2cDf4CqiPKVxzYNhJ3Kwbr7FrACBdLnzEcZFrxgfIlROjilgHb+d8dBUpllAEfO0H5njE1t0wEYJSFp8LCousDOCBXDM+QK605JpgXBGTWtUR8Y+K/gxEwOcKIPFbS3YykwZbirXSGTs02pLe4pnbD2dl0AuMjtw1D1pYrIuRXDM+QK4vyNBh/MIynAduUSaNUlz1Ap11Y+iFuy3yuH04K0N5FTfV9FH/OTg9MjXHCVlZWWZ8gFxpyTUCR5+4s2sBPIcbjkF9xUWu7QK58iQk/6RFDAAAYHugiAEAYGfYRsY8GwAAPkzvmhDifyprmJeFHLPxAAAAAElFTkSuQmCC
    Each month of the report another month is added to row and column.
    Just to make things simple the figure actually needs to be percentage rather than number, but baby steps!

    Thanks for any pointers....

  • Atyeo9 - Tuesday, March 20, 2018 10:14 AM

    My head is well and truly mashed and I could do with some help please...
    I need to write a script to count the number of records opened and closed in certain dates.  This will require a pivot eventually but essentially we're looking at two tables - one has the open date, the other the closed date.  Both have a matching id.  So far so good.  Where I'm struggling is that I need to do a monthly breakdown that needs to be dynamic and increase each month to show the number of records closed in a given month number for a given month.   I'm having difficulty even explaining it let alone coding it!

    Example: 
    10 cases are opened in January
    12 in Feb
    3 in March

    Of the 10 opened in January, 2 are closed in January (Month 1), 3 are closed in February (Month 2) and 5 are closed in March (Month 3)
    Of the 12 opened in February, 7 are closed in February (Month 1), 1 in March (Month 2)
    Of the 3 opened in March, 1 is closed in March (Month 1)

    This would therefore be reflected something like:
    data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWIAAABKCAYAAACB1F6VAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAA3GSURBVHhe7Z0NuqosEMc573Kk5Ry7y4mWU57lpNvpnQFUJDS1TKD/7z4995gfNIDDMOjMz+12u0spBZhHXdcC9RUfubYL5MoTX/4f+tzNnwAAAD7F/d6rXihiAADYgdvtZv+yitjVzGCcnx+uruFIBvYn13aBXHkSkv8/+z8AAICdgCIGAICdGSri+iwOZDb//BxFZb/qqcRxdN8L6DLffM1PYevrcK7tF5ZNZKrF+fAjjltVVNf27Se2NuH+dxB+VQdJqR8vOS8FubrfaD6z+msKclXHTqafuf1wAQGLWAopK1H5v5C+qCTts5urWVoBCVCrc9rycCc7KFFc79pvpT9XMV/xRUkK/ZiUDNX7siqOWS4jT9ePriV1rbl9KGK5+NxjI9StlasQ6vBeHRZQxIUoSymaZlh7FVVIWZZ2C/SUQqlGnJPVWGRpn6lt6eah+6anvIqbEkL9Oy9UFLEQdz+uzwdt5TX0W5YpmYjl0kpTiVP7M8qTULIWdWO3J4lYLnkSt/tNnNqGot9TikZ4P/Ulgj7i4pcEr/6cG5BHKir812626FEmYK7b0eesO5vZb6bvrQXA0w1vpHRM/82m3xtRnC6irEasYn8kHmxbd8PZqUcW3q1XvzKcehq6RNopHH+88mj0PlI5weld/Seqmto20Ncl9QNZV+JPF8O/ldrs7EzRBr9tonz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Y0i0D0M/e9NtIbrMFdf0z9srK8OgXAR+j4L2aRq/Mdw+M9bv5hzDTO3bCl0m5Bow5xhmal8EBCxiKaT7GnMLx3OQtM9u7gsNCn6Ggj2yMnDjHhuh2rgY10KoQ7yN/W3kmvEBcuVHQBEXoiylaLzoGhzhbCzO7yeZl6GAFLWOabxxnAfJQbqdgD76pZJAYBKwA7lmfIBcORL0ERe/pL6qv0FwjaoiJfNrN1tmZtLQ3+qpQX/sQ8wF51qT8Ri2yLLxJky5rwQeAu8k14wPkCs/wot1HGWNqqML+M5uiYdXiFur03EFjGTS4GsNEmnelGgGUdVoPyn69jpTEde2yLLxMnaQ0XGOLgj+Hg+5ZnyAXLkRVsRUIcYoNlo17JZYkElD+5cdC1VP6V23gRSq3Vm86IfeIyuDlocHEfiIoyPXjA+QKytGFDHpls49Yd0SIcU2cDf4CqiPKVxzYNhJ3Kwbr7FrACBdLnzEcZFrxgfIlROjilgHb+d8dBUpllAEfO0H5njE1t0wEYJSFp8LCousDOCBXDM+QK605JpgXBGTWtUR8Y+K/gxEwOcKIPFbS3YykwZbirXSGTs02pLe4pnbD2dl0AuMjtw1D1pYrIuRXDM+QK4vyNBh/MIynAduUSaNUlz1Ap11Y+iFuy3yuH04K0N5FTfV9FH/OTg9MjXHCVlZWWZ8gFxpyTUCR5+4s2sBPIcbjkF9xUWu7QK58iQk/6RFDAAAYHugiAEAYGfYRsY8GwAAPkzvmhDifyprmJeFHLPxAAAAAElFTkSuQmCC
    Each month of the report another month is added to row and column.
    Just to make things simple the figure actually needs to be percentage rather than number, but baby steps!

    Thanks for any pointers....

    I'd probably generate criteria for the entire year and then just leave some months invisible in the actual report. When generating the criteria, I'd include the rows and columns they apply to.

  • patrickmcginnis59 10839 - Tuesday, March 20, 2018 11:52 AM

    Atyeo9 - Tuesday, March 20, 2018 10:14 AM

    My head is well and truly mashed and I could do with some help please...
    I need to write a script to count the number of records opened and closed in certain dates.  This will require a pivot eventually but essentially we're looking at two tables - one has the open date, the other the closed date.  Both have a matching id.  So far so good.  Where I'm struggling is that I need to do a monthly breakdown that needs to be dynamic and increase each month to show the number of records closed in a given month number for a given month.   I'm having difficulty even explaining it let alone coding it!

    Example: 
    10 cases are opened in January
    12 in Feb
    3 in March

    Of the 10 opened in January, 2 are closed in January (Month 1), 3 are closed in February (Month 2) and 5 are closed in March (Month 3)
    Of the 12 opened in February, 7 are closed in February (Month 1), 1 in March (Month 2)
    Of the 3 opened in March, 1 is closed in March (Month 1)

    This would therefore be reflected something like:
    data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWIAAABKCAYAAACB1F6VAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAA3GSURBVHhe7Z0NuqosEMc573Kk5Ry7y4mWU57lpNvpnQFUJDS1TKD/7z4995gfNIDDMOjMz+12u0spBZhHXdcC9RUfubYL5MoTX/4f+tzNnwAAAD7F/d6rXihiAADYgdvtZv+yitjVzGCcnx+uruFIBvYn13aBXHkSkv8/+z8AAICdgCIGAICdGSri+iwOZDb//BxFZb/qqcRxdN8L6DLffM1PYevrcK7tF5ZNZKrF+fAjjltVVNf27Se2NuH+dxB+VQdJqR8vOS8FubrfaD6z+msKclXHTqafuf1wAQGLWAopK1H5v5C+qCTts5urWVoBCVCrc9rycCc7KFFc79pvpT9XMV/xRUkK/ZiUDNX7siqOWS4jT9ePriV1rbl9KGK5+NxjI9StlasQ6vBeHRZQxIUoSymaZlh7FVVIWZZ2C/SUQqlGnJPVWGRpn6lt6eah+6anvIqbEkL9Oy9UFLEQdz+uzwdt5TX0W5YpmYjl0kpTiVP7M8qTULIWdWO3J4lYLnkSt/tNnNqGot9TikZ4P/Ulgj7i4pcEr/6cG5BHKir812626FEmYK7b0eesO5vZb6bvrQXA0w1vpHRM/82m3xtRnC6irEasYn8kHmxbd8PZqUcW3q1XvzKcehq6RNopHH+88mj0PlI5weld/Seqmto20Ncl9QNZV+JPF8O/ldrs7EzRBr9ton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EY0i0D0M/e9NtIbrMFdf0z9srK8OgXAR+j4L2aRq/Mdw+M9bv5hzDTO3bCl0m5Bow5xhmal8EBCxiKaT7GnMLx3OQtM9u7gsNCn6Ggj2yMnDjHhuh2rgY10KoQ7yN/W3kmvEBcuVHQBEXoiylaLzoGhzhbCzO7yeZl6GAFLWOabxxnAfJQbqdgD76pZJAYBKwA7lmfIBcORL0ERe/pL6qv0FwjaoiJfNrN1tmZtLQ3+qpQX/sQ8wF51qT8Ri2yLLxJky5rwQeAu8k14wPkCs/wot1HGWNqqML+M5uiYdXiFur03EFjGTS4GsNEmnelGgGUdVoPyn69jpTEde2yLLxMnaQ0XGOLgj+Hg+5ZnyAXLkRVsRUIcYoNlo17JZYkElD+5cdC1VP6V23gRSq3Vm86IfeIyuDlocHEfiIoyPXjA+QKytGFDHpls49Yd0SIcU2cDf4CqiPKVxzYNhJ3Kwbr7FrACBdLnzEcZFrxgfIlROjilgHb+d8dBUpllAEfO0H5njE1t0wEYJSFp8LCousDOCBXDM+QK605JpgXBGTWtUR8Y+K/gxEwOcKIPFbS3YykwZbirXSGTs02pLe4pnbD2dl0AuMjtw1D1pYrIuRXDM+QK4vyNBh/MIynAduUSaNUlz1Ap11Y+iFuy3yuH04K0N5FTfV9FH/OTg9MjXHCVlZWWZ8gFxpyTUCR5+4s2sBPIcbjkF9xUWu7QK58iQk/6RFDAAAYHugiAEAYGfYRsY8GwAAPkzvmhDifyprmJeFHLPxAAAAAElFTkSuQmCC
    Each month of the report another month is added to row and column.
    Just to make things simple the figure actually needs to be percentage rather than number, but baby steps!

    Thanks for any pointers....

    I'd probably generate criteria for the entire year and then just leave some months invisible in the actual report. When generating the criteria, I'd include the rows and columns they apply to.

    Example of creating criteria for instance, first create an index for the rows and columns, then attach attributes to them that could be parameters for gathering the actual totals to match up with it:


    WITH MonthPtr (OFFST) AS (
    SELECT 0 OFFST UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5
    UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION SELECT 10 UNION SELECT 11
    )
    ,
    MonthMatrix (MonthLine, MonthCol) AS
    (
    SELECT C.OFFST MonthCol, R.OFFST MonthRow FROM MonthPtr C CROSS JOIN MonthPtr R
    )
    ,
    DateStartDat AS (SELECT CONVERT(DATETIME,'2018-01-01') DateStart)
    ,
    MonthActualStart (MonthLine, MonthCol, OpenStart, CloseStart)
    AS
    (
    SELECT MonthLine, MonthCol, DATEADD(MM,MonthLine,DateStart) OpenStart, DATEADD(MM,MonthLine+MonthCol,DateStart) CloseStart FROM MonthMatrix CROSS JOIN DateStartDat
    )
    ,
    MonthActualSelectCalc (MonthLine, MonthCol, OpenStart, OpenEnd, CloseStart, CloseEnd)
    AS
    (
    SELECT MonthLine, MonthCol,OpenStart, DATEADD(DD,-1,DATEADD(MM,1,OpenStart)) OpenEnd, CloseStart, DATEADD(DD,-1,DATEADD(MM,1,CloseStart)) CloseEnd
    FROM MonthActualStart
    )
    ,
    MonthActualSelect (MonthLine, LabelLine, MonthCol, LabelCol, OpenStart, OpenEnd, CloseStart, CloseEnd)
    AS
    (
    SELECT MonthLine, DATENAME(MM,OpenStart), MonthCol, DATENAME(MM,CloseStart), OpenStart, OpenEnd, CloseStart, CloseEnd
    FROM MonthActualSelectCalc
    -- USE THIS CRITERIA TO KEEP IT ALL WITHIN A YEAR IF NEEDED
    WHERE DATEPART(YY,OpenStart) = DATEPART(YY,CloseStart)
    )
    -- THEN USE THESE COLUMNS TO MATCH THE LINES AND COLUMNS TO ACTUAL CRITERIA TO SELECT YOUR DATA
    -- OBVIOUSLY LABEL COL MIGHT NOT BE NEEDED I GUESS
    -- ALSO I ADMIT TO USING ZERO'S ORIGIN TO SPECIFY LINES AND COLUMNS LOL
    SELECT * FROM MonthActualSelect
    ORDER BY MonthLine, MonthCol

  • Atyeo9 - Tuesday, March 20, 2018 10:14 AM

    My head is well and truly mashed and I could do with some help please...
    I need to write a script to count the number of records opened and closed in certain dates.  This will require a pivot eventually but essentially we're looking at two tables - one has the open date, the other the closed date.  Both have a matching id.  So far so good.  Where I'm struggling is that I need to do a monthly breakdown that needs to be dynamic and increase each month to show the number of records closed in a given month number for a given month.   I'm having difficulty even explaining it let alone coding it!

    Example: 
    10 cases are opened in January
    12 in Feb
    3 in March

    Of the 10 opened in January, 2 are closed in January (Month 1), 3 are closed in February (Month 2) and 5 are closed in March (Month 3)
    Of the 12 opened in February, 7 are closed in February (Month 1), 1 in March (Month 2)
    Of the 3 opened in March, 1 is closed in March (Month 1)

    This would therefore be reflected something like:
    data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWIAAABKCAYAAACB1F6VAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAA3GSURBVHhe7Z0NuqosEMc573Kk5Ry7y4mWU57lpNvpnQFUJDS1TKD/7z4995gfNIDDMOjMz+12u0spBZhHXdcC9RUfubYL5MoTX/4f+tzNnwAAAD7F/d6rXihiAADYgdvtZv+yitjVzGCcnx+uruFIBvYn13aBXHkSkv8/+z8AAICdgCIGAICdGSri+iwOZDb//BxFZb/qqcRxdN8L6DLffM1PYevrcK7tF5ZNZKrF+fAjjltVVNf27Se2NuH+dxB+VQdJqR8vOS8FubrfaD6z+msKclXHTqafuf1wAQGLWAopK1H5v5C+qCTts5urWVoBCVCrc9rycCc7KFFc79pvpT9XMV/xRUkK/ZiUDNX7siqOWS4jT9ePriV1rbl9KGK5+NxjI9StlasQ6vBeHRZQxIUoSymaZlh7FVVIWZZ2C/SUQqlGnJPVWGRpn6lt6eah+6anvIqbEkL9Oy9UFLEQdz+uzwdt5TX0W5YpmYjl0kpTiVP7M8qTULIWdWO3J4lYLnkSt/tNnNqGot9TikZ4P/Ulgj7i4pcEr/6cG5BHKir812626FEmYK7b0eesO5vZb6bvrQXA0w1vpHRM/82m3xtRnC6irEasYn8kHmxbd8PZqUcW3q1XvzKcehq6RNopHH+88mj0PlI5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xLk6wqJUWWKx7lD+LxToAAEgZKGIAANiZoSK2TyGEY0i0D0M/e9NtIbrMFdf0z9srK8OgXAR+j4L2aRq/Mdw+M9bv5hzDTO3bCl0m5Bow5xhmal8EBCxiKaT7GnMLx3OQtM9u7gsNCn6Ggj2yMnDjHhuh2rgY10KoQ7yN/W3kmvEBcuVHQBEXoiylaLzoGhzhbCzO7yeZl6GAFLWOabxxnAfJQbqdgD76pZJAYBKwA7lmfIBcORL0ERe/pL6qv0FwjaoiJfNrN1tmZtLQ3+qpQX/sQ8wF51qT8Ri2yLLxJky5rwQeAu8k14wPkCs/wot1HGWNqqML+M5uiYdXiFur03EFjGTS4GsNEmnelGgGUdVoPyn69jpTEde2yLLxMnaQ0XGOLgj+Hg+5ZnyAXLkRVsRUIcYoNlo17JZYkElD+5cdC1VP6V23gRSq3Vm86IfeIyuDlocHEfiIoyPXjA+QKytGFDHpls49Yd0SIcU2cDf4CqiPKVxzYNhJ3Kwbr7FrACBdLnzEcZFrxgfIlROjilgHb+d8dBUpllAEfO0H5njE1t0wEYJSFp8LCousDOCBXDM+QK605JpgXBGTWtUR8Y+K/gxEwOcKIPFbS3YykwZbirXSGTs02pLe4pnbD2dl0AuMjtw1D1pYrIuRXDM+QK4vyNBh/MIynAduUSaNUlz1Ap11Y+iFuy3yuH04K0N5FTfV9FH/OTg9MjXHCVlZWWZ8gFxpyTUCR5+4s2sBPIcbjkF9xUWu7QK58iQk/6RFDAAAYHugiAEAYGfYRsY8GwAAPkzvmhDifyprmJeFHLPxAAAAAElFTkSuQmCC
    Each month of the report another month is added to row and column.
    Just to make things simple the figure actually needs to be percentage rather than number, but baby steps!

    Thanks for any pointers....

    It's pretty simple.  Calculate your stuff vertically, as normal.  Then do a "Dynamic Crosstab".  Please see the following article for details. 
    http://www.sqlservercentral.com/articles/Crosstab/65048/

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply