goup by on sub query

  • Hi,

    I have relisted this from a post I placed about 2 weeks ago as I didnt explain myself very well first time round and was unable to give any sample data. ( i have since discovered the "Generate Script" Wizard, happy days:-)) For those of you that replied I applogise and hope now to be able to to supply you with some sample data.

    Original Post, if your interested

    I will try an explain what I'm trying to achieve.

    I have a dataset (sample data attached in a Create/Insert Script) approx 1700 rows hence the .txt file. This file shows patients that attend our Accident and emergency dept over 3 months. (feb, mar april).

    I the have the following script which identifies patients that returned under the Flags of "reattender" and "unplanned". This gives us 50 rows returned. please ignore comments

    --------------------------------------------------------------------------------------------

    SELECT

    (

    select COUNT(*)

    from dbo.PS_AE_Delete

    where (CONVERT(date, arrival, 101) >= '2011-02-01 00:00')

    AND (CONVERT(date, arrival, 101) <= '2011-04-30 23:59')

    and [Att_Type] = 'New Attender' ) as New_attender_Count

    ,

    F.pat_pid as Patient_ID,

    F.Arrival as F_Att_Date,

    F.Dept as F_Att_Site,

    --F.atd_id as F_Att_ID,

    --F.atd_num as F_Att_Num,

    F.Att_Seq_No as F_Att_Seq_No,

    F.Att_Type as F_Att_Att_Type,

    R.Arrival as R_Att_Date,

    R.Dept as R_Att_Site,

    --R.atd_id as R_Att_ID,

    --R.atd_num as R_Att_Num,

    R.Att_Seq_No as R_Att_Seq_No,

    R.Att_Type as R_Att_Att_Type,

    R.Return_Type as R_Att__return_Type,

    year(r.Arrival) as Year,

    month(r.Arrival) as month

    --DATEDIFF(dd, F.arrival, R.arrival) as Days_Diff

    from

    --- F = previous R = readmission

    --previous attendance F

    (SELECT arrival, pat_pid, Att_Seq_No, Att_Type, Return_Type, Dept

    FROM dbo.PS_AE_Delete

    ) AS F

    INNER JOIN

    -- re attendance R

    (SELECT arrival, pat_pid, Att_Seq_No, Att_Type, Return_Type, Dept

    FROM dbo.PS_AE_Delete AS re_att_1

    where (Att_Type = 'Reattender') AND (Return_Type = 'Unplanned')

    AND (CONVERT(date, arrival, 101) >= '2011-02-01 00:00')

    AND (CONVERT(date, arrival, 101) <= '2011-04-30 23:59')) AS R

    ON F.pat_pid = R.pat_pid

    AND F.Att_Seq_No + 1 = R.Att_Seq_No

    --AND DATEDIFF(dd, F.arrival, R.arrival) < '8'

    order by R.Dept ,year(r.Arrival) ,

    month(r.Arrival)

    ------------------------------------------------------------------------------

    In the first column I have attempted to put in a total which currently shows 1639. this is the total for the full 3 months.

    What I would like it to show is a total for each R_Att_Site ("ABC" or "DEF") , Year and month .

    I am presuming that this will have to be grouped some how in the sub query at the begining of my script.

    I would expect to see (from the sample data provided) the folloing resuults.

    1) Still see 50 rows of data returned from the query

    2) Instead of seeing "1639" in every row I would like to see the following the results in the second .txt file. Basically the total in the 1st column is grouped by SITE, YEAR then MONTH.

    Once again appolgies of last times effort and hope the attatched helps you to help me.

    Thanks in adavance

  • Why start a new thread? Try this:

    SELECT

    New_attender_Count = COUNT(*) OVER (PARTITION BY R.Dept),

    --New_attender_Count = (

    -- select COUNT(*)

    -- from dbo.PS_AE_Delete

    -- where (CONVERT(date, arrival, 101) >= '2011-02-01 00:00')

    -- AND (CONVERT(date, arrival, 101) <= '2011-04-30 23:59')

    -- and [Att_Type] = 'New Attender'

    -- ),

    F.pat_pid as Patient_ID,

    F.Arrival as F_Att_Date,

    F.Dept as F_Att_Site,

    F.Att_Seq_No as F_Att_Seq_No,

    F.Att_Type as F_Att_Att_Type,

    R.Arrival as R_Att_Date,

    R.Dept as R_Att_Site,

    R.Att_Seq_No as R_Att_Seq_No,

    R.Att_Type as R_Att_Att_Type,

    R.Return_Type as R_Att__return_Type,

    year(r.Arrival) as Year,

    month(r.Arrival) as month

    --previous attendance F

    FROM dbo.PS_AE_Delete f

    -- re attendance (readmission) R

    INNER JOIN dbo.PS_AE_Delete r

    ON F.pat_pid = R.pat_pid

    AND F.Att_Seq_No + 1 = R.Att_Seq_No

    --AND DATEDIFF(dd, F.arrival, R.arrival) < '8'

    where (r.Att_Type = 'Reattender')

    AND (r.Return_Type = 'Unplanned')

    AND (CONVERT(date, r.arrival, 101) >= '2011-02-01 00:00')

    AND (CONVERT(date, r.arrival, 101) <= '2011-04-30 23:59')

    order by R.Dept, year(r.Arrival), month(r.Arrival)

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Many thanks for your speedy reply. Works fine.

    The next think i was trying to achieve is to gain another column which has the total for each grouping period based on the sub query at the beginig of the script.

    the script below is what i would use to gain the figures and the attached script is what I would expect to see the results as. Not sure how to tackle this as you are taking a single figure and applying it to multiple rows.??????

    HOW TO GET FIGURES ---- attcahed .txt file is expected results

    select COUNT(*) as count_to_be_repeated_for_each, Dept, year(Arrival),month(Arrival)

    from dbo.PS_AE_Delete

    where (CONVERT(date, arrival, 101) >= '2011-02-01 00:00')

    AND (CONVERT(date, arrival, 101) <= '2011-04-30 23:59')

    and [Att_Type] = 'New Attender'

    group by Dept, year(Arrival),month(Arrival)

  • Add this to your SELECT list:

    Another_New_attender_Count = COUNT(*) OVER (PARTITION BY R.Dept, YEAR(Arrival), MONTH(Arrival))

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Many Thanks for your reply

    I have already added in your suggestion to the original query and it works fine.

    I now need to add in the total numner of people attended against each of the rows returned by the original query.

    If you look at the original table it contains 1717 records. Of these , 50 are returned in the main query.

    In the sub query ,I am trying to gain a value for all attendances assisged aginst the returned rows dependant on the DEPT, YEAR and MONTH.

    i know the following gives me the figures, I just dont know how, if possible, to assign them to the rows returned in the bulk of the query.

    -----------------------------------------------------------------------------------

    select COUNT(*) as count_to_be_repeated_for_each, Dept, year(Arrival),month(Arrival)

    from dbo.PS_AE_Delete

    where (CONVERT(date, arrival, 101) >= '2011-02-01 00:00')

    AND (CONVERT(date, arrival, 101) <= '2011-04-30 23:59')

    and [Att_Type] = 'New Attender'

    group by Dept, year(Arrival),month(Arrival)

    ----------------------------------------------------------------------------------

    Therefore in the first column i would expect to see "277" in the first group of DEPT, Yr, Month, Then a block of "320"'s then "390"'s etc etc.

    please see my expected results in the .txt file called "create and insert expected results - second column - SQL Central.txt" from my previous post. This will show you better what I'm trying to achive

    If this is not possible then I will have to look for another solution.

    Thanks in advance for you replies

  • p.stevens76 (10/3/2011)


    select COUNT(*) as count_to_be_repeated_for_each, Dept, year(Arrival),month(Arrival)

    from dbo.PS_AE_Delete

    where (CONVERT(date, arrival, 101) >= '2011-02-01 00:00')

    AND (CONVERT(date, arrival, 101) <= '2011-04-30 23:59')

    and [Att_Type] = 'New Attender'

    group by Dept, year(Arrival),month(Arrival)

    Isn't this query the same as the last one?

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • No, it's an addition. trying to work through this in stages. This is the last stage.

    Sorry for the confusion.

  • p.stevens76 (10/3/2011)


    No, it's an addition. trying to work through this in stages. This is the last stage.

    Sorry for the confusion.

    The two queries (subqueries) look the same to me:

    select COUNT(*) as count_to_be_repeated_for_each, Dept, year(Arrival),month(Arrival)

    from dbo.PS_AE_Delete

    where (CONVERT(date, arrival, 101) >= '2011-02-01 00:00')

    AND (CONVERT(date, arrival, 101) <= '2011-04-30 23:59')

    and [Att_Type] = 'New Attender'

    group by Dept, year(Arrival),month(Arrival)

    select COUNT(*) as count_to_be_repeated_for_each, Dept, year(Arrival),month(Arrival)

    from dbo.PS_AE_Delete

    where (CONVERT(date, arrival, 101) >= '2011-02-01 00:00')

    AND (CONVERT(date, arrival, 101) <= '2011-04-30 23:59')

    and [Att_Type] = 'New Attender'

    group by Dept, year(Arrival),month(Arrival)

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • They are, I'm trying to achive the results in my .txt file in one query.

    The first part of my query is the bit i'm stuck with. It give sme the figures i need but not on each row.

    The results from the subquery at the top need assigned to each row of the main query depeneind on DEPT, Year and month.

    please see my expected results attached

    Thanks

  • p.stevens76 (10/3/2011)


    They are, I'm trying to achive the results in my .txt file in one query.

    The first part of my query is the bit i'm stuck with. It give sme the figures i need but not on each row.

    The results from the subquery at the top need assigned to each row of the main query depeneind on DEPT, Year and month.

    please see my expected results attached

    Thanks

    Ok, try this. I've added in the dept so you can better understand what the window function (...OVER...) is doing.

    DECLARE @Startdate DATETIME, @Enddate DATETIME

    SET @Startdate = CONVERT(DATETIME,'2011-02-01 00:00',101)

    SET @Enddate = CONVERT(DATETIME,'2011-05-01 00:00',101)

    SELECT

    R.Dept,

    New_attender_Count = COUNT(*) OVER (PARTITION BY R.Dept, YEAR(r.Arrival), MONTH(r.Arrival)),

    F.pat_pid as Patient_ID,

    F.Arrival as F_Att_Date,

    F.Dept as F_Att_Site,

    F.Att_Seq_No as F_Att_Seq_No,

    F.Att_Type as F_Att_Att_Type,

    R.Arrival as R_Att_Date,

    R.Dept as R_Att_Site,

    R.Att_Seq_No as R_Att_Seq_No,

    R.Att_Type as R_Att_Att_Type,

    R.Return_Type as R_Att__return_Type,

    year(r.Arrival) as Year,

    month(r.Arrival) as month

    FROM dbo.PS_AE_Delete f --previous attendance F

    INNER JOIN dbo.PS_AE_Delete r -- re attendance (readmission) R

    ON F.pat_pid = R.pat_pid

    AND F.Att_Seq_No + 1 = R.Att_Seq_No

    WHERE r.Att_Type = 'Reattender'

    AND r.Return_Type = 'Unplanned'

    AND r.arrival >= @Startdate

    AND r.arrival < @Enddate

    AND DATEDIFF(dd, F.arrival, R.arrival) < '8'

    ORDER BY R.Dept, year(r.Arrival), month(r.Arrival)

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • OK thanks, I see what the Over is doing by counttng the rows depending on the grouping. This is fine.

    Further to that I would like to also have an aditional column which shows total attendances again grouped the same.

    If you run the script below you will see that the top 11 rows contain a value of 277 for [R_Att_Site] = ABC and year = 2011 and Month = 2.

    this means that in that month we had 277 attendances to that dept of of those there were 11 that were reattenders.

    Is this possible or would it have to be done as a seperat e query

    thanks

    --------------------------------------------------------------------------------

    GO

    /****** Object: Table [dbo].[PS_REsults] Script Date: 10/03/2011 14:19:25 ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    SET ANSI_PADDING ON

    GO

    CREATE TABLE [dbo].[PS_REsults](

    [New_attender_Count] [int] NULL,

    [Patient_ID] [int] NULL,

    [F_Att_Date] [datetime] NULL,

    [F_Att_Site] [varchar](3) NULL,

    [F_Att_Seq_No] [bigint] NULL,

    [F_Att_Att_Type] [varchar](12) NOT NULL,

    [R_Att_Date] [datetime] NULL,

    [R_Att_Site] [varchar](3) NULL,

    [R_Att_Seq_No] [bigint] NULL,

    [R_Att_Att_Type] [varchar](12) NOT NULL,

    [R_Att__return_Type] [varchar](80) NULL,

    [Year] [int] NULL,

    [month] [int] NULL

    ) ON [PRIMARY]

    GO

    SET ANSI_PADDING OFF

    GO

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (277, 7775, CAST(0x00009E8300138030 AS DateTime), N'ABC', 3, N'New Attender', CAST(0x00009E87015FD650 AS DateTime), N'ABC', 4, N'Reattender', N'Unplanned', 2011, 2)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (277, 7775, CAST(0x00009EA200B09AF0 AS DateTime), N'DEF', 3, N'New Attender', CAST(0x00009E87015FD650 AS DateTime), N'ABC', 4, N'Reattender', N'Unplanned', 2011, 2)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (277, 8752, CAST(0x00009EBC00D6C860 AS DateTime), N'DEF', 1, N'New Attender', CAST(0x00009E86012A8DB0 AS DateTime), N'ABC', 2, N'Reattender', N'Unplanned', 2011, 2)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (277, 8752, CAST(0x00009E85011D1860 AS DateTime), N'ABC', 1, N'New Attender', CAST(0x00009E86012A8DB0 AS DateTime), N'ABC', 2, N'Reattender', N'Unplanned', 2011, 2)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (277, 8752, CAST(0x00009EC601292E20 AS DateTime), N'ABC', 1, N'New Attender', CAST(0x00009E86012A8DB0 AS DateTime), N'ABC', 2, N'Reattender', N'Unplanned', 2011, 2)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (277, 8752, CAST(0x00009ECA00255A80 AS DateTime), N'DEF', 1, N'New Attender', CAST(0x00009E86012A8DB0 AS DateTime), N'ABC', 2, N'Reattender', N'Unplanned', 2011, 2)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (277, 8752, CAST(0x00009E8200B54640 AS DateTime), N'ABC', 1, N'New Attender', CAST(0x00009E86012A8DB0 AS DateTime), N'ABC', 2, N'Reattender', N'Unplanned', 2011, 2)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (277, 82888, CAST(0x00009E80007F7100 AS DateTime), N'DEF', 1, N'New Attender', CAST(0x00009E7E0102BA60 AS DateTime), N'ABC', 2, N'Reattender', N'Unplanned', 2011, 2)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (277, 82888, CAST(0x00009E8400E5E390 AS DateTime), N'ABC', 1, N'New Attender', CAST(0x00009E7E0102BA60 AS DateTime), N'ABC', 2, N'Reattender', N'Unplanned', 2011, 2)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (277, 88588, CAST(0x00009E9200C693F0 AS DateTime), N'ABC', 2, N'New Attender', CAST(0x00009E7D00A0ACD0 AS DateTime), N'ABC', 3, N'Reattender', N'Unplanned', 2011, 2)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (277, 88588, CAST(0x00009EA400970FE0 AS DateTime), N'ABC', 2, N'New Attender', CAST(0x00009E7D00A0ACD0 AS DateTime), N'ABC', 3, N'Reattender', N'Unplanned', 2011, 2)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (320, 78728, CAST(0x00009E8700A0ACD0 AS DateTime), N'ABC', 3, N'New Attender', CAST(0x00009EB400B58C90 AS DateTime), N'ABC', 4, N'Reattender', N'Unplanned', 2011, 3)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (320, 25558, CAST(0x00009EB300DA5A70 AS DateTime), N'ABC', 4, N'New Attender', CAST(0x00009EB30112A880 AS DateTime), N'ABC', 5, N'Reattender', N'Unplanned', 2011, 3)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (320, 88282, CAST(0x00009EC40159CB70 AS DateTime), N'ABC', 1, N'New Attender', CAST(0x00009EA000CED150 AS DateTime), N'ABC', 2, N'Reattender', N'Unplanned', 2011, 3)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (320, 88282, CAST(0x00009ECF014C9C70 AS DateTime), N'ABC', 1, N'New Attender', CAST(0x00009EA000CED150 AS DateTime), N'ABC', 2, N'Reattender', N'Unplanned', 2011, 3)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (320, 88282, CAST(0x00009E9E00E48400 AS DateTime), N'ABC', 1, N'New Attender', CAST(0x00009EA000CED150 AS DateTime), N'ABC', 2, N'Reattender', N'Unplanned', 2011, 3)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (320, 7752, CAST(0x00009EA400B5D2E0 AS DateTime), N'ABC', 7, N'New Attender', CAST(0x00009EA7015DEA20 AS DateTime), N'ABC', 8, N'Reattender', N'Unplanned', 2011, 3)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (320, 825, CAST(0x00009EBD011C8BC0 AS DateTime), N'ABC', 1, N'New Attender', CAST(0x00009EB00152A750 AS DateTime), N'ABC', 2, N'Reattender', N'Unplanned', 2011, 3)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (320, 825, CAST(0x00009EAB00A67160 AS DateTime), N'ABC', 1, N'New Attender', CAST(0x00009EB00152A750 AS DateTime), N'ABC', 2, N'Reattender', N'Unplanned', 2011, 3)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (320, 825, CAST(0x00009ECA012814E0 AS DateTime), N'DEF', 1, N'New Attender', CAST(0x00009EB00152A750 AS DateTime), N'ABC', 2, N'Reattender', N'Unplanned', 2011, 3)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (320, 875, CAST(0x00009E9600BD3D50 AS DateTime), N'ABC', 1, N'New Attender', CAST(0x00009EA60145BEA0 AS DateTime), N'ABC', 2, N'Reattender', N'Unplanned', 2011, 3)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (320, 875, CAST(0x00009EA60145BEA0 AS DateTime), N'ABC', 2, N'Reattender', CAST(0x00009EB400B16DE0 AS DateTime), N'ABC', 3, N'Reattender', N'Unplanned', 2011, 3)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (320, 2882, CAST(0x00009E8B00E6FCD0 AS DateTime), N'ABC', 2, N'New Attender', CAST(0x00009E9D0084A8F0 AS DateTime), N'ABC', 3, N'Reattender', N'Unplanned', 2011, 3)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (390, 2228, CAST(0x00009ECC00E92F50 AS DateTime), N'ABC', 3, N'New Attender', CAST(0x00009ECF00827670 AS DateTime), N'ABC', 4, N'Reattender', N'Unplanned', 2011, 4)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (390, 87725, CAST(0x00009ECB013BDB60 AS DateTime), N'ABC', 3, N'New Attender', CAST(0x00009ECD00BBDDC0 AS DateTime), N'ABC', 4, N'Reattender', N'Unplanned', 2011, 4)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (390, 82578, CAST(0x00009EC5014BC980 AS DateTime), N'ABC', 10, N'New Attender', CAST(0x00009EC60174FC60 AS DateTime), N'ABC', 11, N'Reattender', N'Unplanned', 2011, 4)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (390, 25785, CAST(0x00009EC201742970 AS DateTime), N'ABC', 4, N'New Attender', CAST(0x00009EC300C4EE10 AS DateTime), N'ABC', 5, N'Reattender', N'Unplanned', 2011, 4)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (390, 27788, CAST(0x00009EBC007F2AB0 AS DateTime), N'ABC', 3, N'New Attender', CAST(0x00009ECB00E67030 AS DateTime), N'ABC', 4, N'Reattender', N'Unplanned', 2011, 4)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (390, 27788, CAST(0x00009ECB00E67030 AS DateTime), N'ABC', 4, N'Reattender', CAST(0x00009ED100A48530 AS DateTime), N'ABC', 5, N'Reattender', N'Unplanned', 2011, 4)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (390, 77882, CAST(0x00009ECD010F5CC0 AS DateTime), N'ABC', 1, N'New Attender', CAST(0x00009ED500F358E0 AS DateTime), N'ABC', 2, N'Reattender', N'Unplanned', 2011, 4)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (390, 72888, CAST(0x00009ED400754770 AS DateTime), N'ABC', 2, N'New Attender', CAST(0x00009ED400D79B50 AS DateTime), N'ABC', 3, N'Reattender', N'Unplanned', 2011, 4)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (390, 78285, CAST(0x00009EBA006A9140 AS DateTime), N'ABC', 4, N'New Attender', CAST(0x00009EBD0115F440 AS DateTime), N'ABC', 5, N'Reattender', N'Unplanned', 2011, 4)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (173, 88852, CAST(0x00009E7F0109DE80 AS DateTime), N'DEF', 2, N'New Attender', CAST(0x00009E840106D910 AS DateTime), N'DEF', 3, N'Reattender', N'Unplanned', 2011, 2)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (173, 88852, CAST(0x00009E840106D910 AS DateTime), N'DEF', 3, N'Reattender', CAST(0x00009E89012BA6F0 AS DateTime), N'DEF', 4, N'Reattender', N'Unplanned', 2011, 2)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (173, 7828, CAST(0x00009E7D00CFEA90 AS DateTime), N'DEF', 3, N'New Attender', CAST(0x00009E840115F440 AS DateTime), N'DEF', 4, N'Reattender', N'Unplanned', 2011, 2)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (173, 7828, CAST(0x00009E840115F440 AS DateTime), N'DEF', 4, N'Reattender', CAST(0x00009E91014D2910 AS DateTime), N'DEF', 5, N'Reattender', N'Unplanned', 2011, 2)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (236, 785, CAST(0x00009EAE0126FBA0 AS DateTime), N'DEF', 1, N'New Attender', CAST(0x00009E9A014AF690 AS DateTime), N'DEF', 2, N'Reattender', N'Unplanned', 2011, 3)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (236, 785, CAST(0x00009E99012A8DB0 AS DateTime), N'DEF', 1, N'New Attender', CAST(0x00009E9A014AF690 AS DateTime), N'DEF', 2, N'Reattender', N'Unplanned', 2011, 3)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (236, 288, CAST(0x00009EA201285B30 AS DateTime), N'DEF', 2, N'New Attender', CAST(0x00009EAA01118F40 AS DateTime), N'DEF', 3, N'Reattender', N'Unplanned', 2011, 3)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (236, 8558, CAST(0x00009EAB00E67030 AS DateTime), N'DEF', 2, N'New Attender', CAST(0x00009EB100F23FA0 AS DateTime), N'DEF', 3, N'Reattender', N'Unplanned', 2011, 3)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (243, 785, CAST(0x00009ED100034BC0 AS DateTime), N'DEF', 4, N'New Attender', CAST(0x00009ED30145BEA0 AS DateTime), N'DEF', 5, N'Reattender', N'Unplanned', 2011, 4)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (243, 8585, CAST(0x00009E9000D6C860 AS DateTime), N'ABC', 2, N'New Attender', CAST(0x00009EC100CD71C0 AS DateTime), N'DEF', 3, N'Reattender', N'Unplanned', 2011, 4)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (243, 8585, CAST(0x00009EBB014086B0 AS DateTime), N'DEF', 2, N'New Attender', CAST(0x00009EC100CD71C0 AS DateTime), N'DEF', 3, N'Reattender', N'Unplanned', 2011, 4)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (243, 885, CAST(0x00009E8700D568D0 AS DateTime), N'ABC', 1, N'New Attender', CAST(0x00009EC600CF17A0 AS DateTime), N'DEF', 2, N'Reattender', N'Unplanned', 2011, 4)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (243, 885, CAST(0x00009EC5015074D0 AS DateTime), N'DEF', 1, N'New Attender', CAST(0x00009EC600CF17A0 AS DateTime), N'DEF', 2, N'Reattender', N'Unplanned', 2011, 4)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (243, 885, CAST(0x00009E95017C2080 AS DateTime), N'DEF', 1, N'New Attender', CAST(0x00009EC600CF17A0 AS DateTime), N'DEF', 2, N'Reattender', N'Unplanned', 2011, 4)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (243, 85552, CAST(0x00009EBA01685A00 AS DateTime), N'DEF', 2, N'New Attender', CAST(0x00009EBB00A81740 AS DateTime), N'DEF', 3, N'Reattender', N'Unplanned', 2011, 4)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (243, 88825, CAST(0x00009EC9018B3BB0 AS DateTime), N'DEF', 1, N'New Attender', CAST(0x00009ECB015074D0 AS DateTime), N'DEF', 2, N'Reattender', N'Unplanned', 2011, 4)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (243, 88587, CAST(0x00009ECF00D94130 AS DateTime), N'DEF', 1, N'New Attender', CAST(0x00009ED000CBCBE0 AS DateTime), N'DEF', 2, N'Reattender', N'Unplanned', 2011, 4)

    INSERT [dbo].[PS_REsults] ([New_attender_Count], [Patient_ID], [F_Att_Date], [F_Att_Site], [F_Att_Seq_No], [F_Att_Att_Type], [R_Att_Date], [R_Att_Site], [R_Att_Seq_No], [R_Att_Att_Type], [R_Att__return_Type], [Year], [month]) VALUES (243, 27787, CAST(0x00009EBE00F285F0 AS DateTime), N'DEF', 1, N'New Attender', CAST(0x00009EC3008D2CA0 AS DateTime), N'DEF', 2, N'Reattender', N'Unplanned', 2011, 4)

Viewing 11 posts - 1 through 10 (of 10 total)

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