Create Status table Column and update

  • I need Status Update column like :

    1)All (both completed and pending i.e which went to Enrollment Analyst step’

    2)Pending

    3)Complete

    Have Main table:

    Create Table [dbo].[tbl_doc_activity] (

    Acivity_id int not null identity(1,1),---identity column

    Entry_id int ,

    Eventy_type_id int,

    Event_value varchar(1023),

    Event_time datetime,

    Username Varchar(200))

    -------And have EVENT LOOK UP TABLE...just giving this table for understanding---

    CREATE TABLE [dbo].[event_look_up](

    [Event_Description] [varchar](50) NULL,

    [Event_Type_Id] [int] NOT NULL)

    Insert into [dbo].[event_look_up]( [Event_Type_Id], Event_description)

    values(1,'STATUS')

    Insert into [dbo].[event_look_up]( [Event_Type_Id], Event_description)

    values(2,'FOLDERNAME')

    Insert into [dbo].[event_look_up]( [Event_Type_Id], Event_description)

    values(3,'sys_Routing_Action')

    Insert into [dbo].[event_look_up]( [Event_Type_Id], Event_description)

    values(4,'sys_WkfStep_Previous')

    Insert into [dbo].[event_look_up]( [Event_Type_Id], Event_description)

    values(5,'sys_WkfStep_Current')

    Insert into [dbo].[event_look_up]( [Event_Type_Id], Event_description)

    values(6,'Pending ')

    ---------------------------getting all records with current step is Enrollment Analyst-------------

    select et.Event_Description, da.* from dbo.tbl_doc_activity da

    inner join [dbo].[event_look_up] et

    on da.Event_Type_Id = et.Event_Type_Id

    where da.Event_Type_Id=5 and da.Event_Value like 'Enrollment Analyst'

    ------Incomplete since it has no additional current_step after "Enrollment_analsyt" : so it is in pending-----

    Insert INTO [dbo].[tbl_doc_activity](Entry_id,Eventy_type_id ,Event_value ,Event_time,Username)

    VALUES(107,1,'Imported','2012-05-12 13:49:03.740','ABD')

    Insert INTO [dbo].[tbl_doc_activity](Entry_id,Eventy_type_id ,Event_value ,Event_time,Username)

    VALUES(107,5,'Enrollment Analyst','2012-05-12 13:49:03.757','ABD2')

    Insert INTO [dbo].[tbl_doc_activity](Entry_id,Eventy_type_id ,Event_value ,Event_time,Username)

    VALUES(107,1,'Routing','2012-05-12 13:49:07.927','ABD3')

    Insert INTO [dbo].[tbl_doc_activity](Entry_id,Eventy_type_id ,Event_value ,Event_time,Username)

    VALUES(107,3,'ENROLLMENT TECHNICIAN','2012-05-12 13:49:07.943','ABD4'

    --These are completed "Enrollment_analsyt_step as their previous step is "enrollment analyst"

    or we can say that it has additional current_step after "Current_step"=Enrollment_analsyt------

    select et.Event_Description, da.* from dbo.tbl_doc_activity da

    inner join [dbo].[event_look_up] et

    on da.Event_Type_Id = et.Event_Type_Id

    where da.Event_Type_Id=4 and da.Event_Value like 'Enrollment Analyst'

    Example:

    ------Completed Enrollment_step since entry has previous step =EA------------------------

    Insert INTO [dbo].[tbl_doc_activity](Entry_id,Eventy_type_id ,Event_value ,Event_time,Username)

    VALUES(108,1,'Routing','2012-05-18 02:03:51.887','ABD')

    Insert INTO [dbo].[tbl_doc_activity](Entry_id,Eventy_type_id ,Event_value ,Event_time,Username)

    VALUES(108,5,'Enrollment Analyst','2012-05-18 02:03:55.560','ABD2')

    Insert INTO [dbo].[tbl_doc_activity](Entry_id,Eventy_type_id ,Event_value ,Event_time,Username)

    VALUES(108,5,'Intake','2012-05-18 02:03:46.373','ABD3')

    Insert INTO [dbo].[tbl_doc_activity](Entry_id,Eventy_type_id ,Event_value ,Event_time,Username)

    VALUES(108,3,'INDEXING','2012-05-18 10:29:01.463','ABD4')

    Insert INTO [dbo].[tbl_doc_activity](Entry_id,Eventy_type_id ,Event_value ,Event_time,Username)

    VALUES(108,4,'Enrollment Analyst','2012-05-18 10:53:06.597','ABD5')

    ------I need to Create some status table like below in which i have: status which tells:

    --1) records which came out of enrollment_analyst step(completed) or whose previous_Step=enrollmet analsyt

    --2) records still in enrollment analsyt i.e they have no current_step after current_step=enrollment_analsyt-----------

    create Table #Status_of_Enrollment

    ( Entry_id int,

    event_type_id int,

    Event_value varchar(30),

    Event_time varchar(30),

    last_updated_user varchar(40),

    Status varchar(40))

    My Final table should look like :

    Entry_id Event_type_idEvent_valueEvent_timeusernameStatus

    108 4Enrollment Analyst2012-05-18 10:53:06.597ABD5Completed

    107 5Enrollment Analyst2012-05-18 02:03:55.560ABD2pending

    I know what to do , but don’t know how to do???

    Any help help is appreciated.

  • Pretty sure I understand what you are looking for but your sample data doesn't match your desired output.

    Take a look at what you stated is desired output.

    107 5 Enrollment Analyst 2012-05-18 02:03:55.560 ABD2 pending

    There are no rows with that time stamp.

    select et.Event_Description, da.*

    from dbo.tbl_doc_activity da

    inner join [dbo].[event_look_up] et

    on da.Eventy_Type_Id = et.Event_Type_Id

    where Entry_ID = 107

    See if something like this will produce the correct results:

    select *, Case Event_Value when 'Enrollment Analyst' then 'Completed' else 'Pending' end

    from

    (

    select et.Event_Description, da.*, ROW_NUMBER() over(partition by Entry_ID order by Event_Time desc) as RowNum

    from dbo.tbl_doc_activity da

    inner join [dbo].[event_look_up] et

    on da.Eventy_Type_Id =

    et.Event_Type_Id

    ) x

    where x.RowNum = 1

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • From your query i am getting all the records whose current_step is not "enrollment_analyst and setting sattus = "pending"

    But I need only those records which are in Current_step ="Enrollment_Analsyt" and those which are "pending " or completed"

  • komal145 (5/23/2012)


    From your query i am getting all the records whose current_step is not "enrollment_analyst and setting sattus = "pending"

    But I need only those records which are in Current_step ="Enrollment_Analsyt" and those which are "pending " or completed"

    Your sample output showed two rows. If you can try to explain more clearly what you are looking for perhaps I can help you get the data you want.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Example of entries which has no current+step=5 and event_value=’enrollment anaylst”---------

    Insert INTO [dbo].[tbl_doc_activity](Entry_id,Eventy_type_id ,Event_value ,Event_time,Username)

    VALUES(10725,1,'Initiated','2012-05-18 16:26:02.987','ADMIN')

    Insert INTO [dbo].[tbl_doc_activity](Entry_id,Eventy_type_id ,Event_value ,Event_time,Username)

    VALUES(10725,5,'QA Technician','2012-05-18 16:26:02.987','ADMIN')

    Insert INTO [dbo].[tbl_doc_activity](Entry_id,Eventy_type_id ,Event_value ,Event_time,Username)

    VALUES(10725,1,'Carrier Exception','2012-05-18 16:27:56.870','ADMIN')

    Insert INTO [dbo].[tbl_doc_activity](Entry_id,Eventy_type_id ,Event_value ,Event_time,Username)

    VALUES(10725,1,'New Info Received','2012-05-18 16:29:16.207','ADMIN')

    -----------------Entry_2----------

    Insert INTO [dbo].[tbl_doc_activity](Entry_id,Eventy_type_id ,Event_value ,Event_time,Username)

    VALUES(10714,1,'Initiated','2012-05-18 16:01:03.143','ADMIN')

    Insert INTO [dbo].[tbl_doc_activity](Entry_id,Eventy_type_id ,Event_value ,Event_time,Username)

    VALUES(10714,5,'Customer Service','2012-05-18 16:01:03.173','ADMIN')

    Insert INTO [dbo].[tbl_doc_activity](Entry_id,Eventy_type_id ,Event_value ,Event_time,Username)

    VALUES(10714,5,'Enrollment Technician','2012-05-18 16:07:03.823','ADMIN')

    Insert INTO [dbo].[tbl_doc_activity](Entry_id,Eventy_type_id ,Event_value ,Event_time,Username)

    VALUES(10714,5,'Customer Service','2012-05-18 16:07:03.827','ADMIN')

    Actuallt I don’t care for records as above..which did not go to Current_step(event_type_id=5) and event_value=”enrollment_analyst”

    I need only entry_id=107,108 which has event_value=”enrollment_analyst”

    And in Current_step(event_type_id=5)

  • So what do you want for output? Try creating a temp table and insert to hold what the desired output should be. I don't get it from your description.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Entry_idevent_type_idEvent_valueevent_timelast_updated_userStatus

    107141Initiated5/18/2012 16:01ADMIN

    107145Customer Service5/18/2012 16:01ADMIN

    107145Enrollment Technicia5/18/2012 16:07ADMIN

    107145Customer Service5/18/2012 16:07ADMIN Pending

    1071Imported5/12/2012 13:49ABD Pending

    1075Enrollment Analyst5/12/2012 13:49ABD2 Pending

    1071Routing5/12/2012 13:49ABD3 Pending

    1073ENROLLMENT TECHNICIA5/12/2012 13:49ABD4 Pending

    1081Routing5/18/2012 2:03ABDComplete

    1085Enrollment Analyst5/18/2012 2:03ABD2Complete

    1085Intake5/18/2012 2:03ABD3Complete

    1083INDEXING5/18/2012 10:29ABD4Complete

    1084Enrollment Analyst5/18/2012 10:53ABD5Complete

    My status table should like above....

  • komal145 (5/23/2012)


    Entry_idevent_type_idEvent_valueevent_timelast_updated_userStatus

    107141Initiated5/18/2012 16:01ADMIN

    107145Customer Service5/18/2012 16:01ADMIN

    107145Enrollment Technicia5/18/2012 16:07ADMIN

    107145Customer Service5/18/2012 16:07ADMIN Pending

    1071Imported5/12/2012 13:49ABD Pending

    1075Enrollment Analyst5/12/2012 13:49ABD2 Pending

    1071Routing5/12/2012 13:49ABD3 Pending

    1073ENROLLMENT TECHNICIA5/12/2012 13:49ABD4 Pending

    1081Routing5/18/2012 2:03ABDComplete

    1085Enrollment Analyst5/18/2012 2:03ABD2Complete

    1085Intake5/18/2012 2:03ABD3Complete

    1083INDEXING5/18/2012 10:29ABD4Complete

    1084Enrollment Analyst5/18/2012 10:53ABD5Complete

    My status table should like above....

    So you want this as a new column in the Event_Description table?

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Yep..new table with status column

  • OK if you really want some help you have to help me understand what you are trying to do. You want a new table with a single column in it? Or is this an Event_Status table? My crystal ball was sent out for repairs, it is not expected back until next week. In the meantime a clear explanation of what you trying to do can probably resolve this pretty quickly.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • I need a event_status table :

    I want status for only those records which have sys_current_step(5) = "enrollmentanalyst"

    and status will complete or pending.

    I need to know the status of records which are in enrollment_analyst queue

    1)if out of Enrollment step(then status = complete ) i.e those records which have additional current_step=5 after current_step="enrollment analyst"

    and

    2)if there is no additional sys_current_step(5) after current_step="enrollment analyst"

    then its status set to "pending"

    hope you understand!!!

  • komal145 (5/23/2012)


    I need a event_status table :

    I want status for only those records which have sys_current_step(5) = "enrollmentanalyst"

    and status will complete or pending.

    I need to know the status of records which are in enrollment_analyst queue

    1)if out of Enrollment step(then status = complete ) i.e those records which have additional current_step=5 after current_step="enrollment analyst"

    and

    2)if there is no additional sys_current_step(5) after current_step="enrollment analyst"

    then its status set to "pending"

    hope you understand!!!

    I understand you want a new table. What does this table hold? What are the columns? Can you provide ddl for this new table?

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Thank you for understanding.

    I need these columns( all of them are tbl_doc_sctivity table) except status column …which has to be derived.

    create Table Status_of_Enrollment

    ( Entry_id int,

    event_type_id int,

    Event_value varchar(30),

    Event_time varchar(30),

    Username varchar(40),

    Status Varchar(40))

  • There is probably a cleaner way to do this but this produces the correct results according to your sample data. I am kind of buried at work or I would have spent some time on this.

    insert Status_of_Enrollment

    select da.Entry_ID, Eventy_type_id, Event_Value, Event_Time, UserName, xyz.Status

    from dbo.tbl_doc_activity da

    inner join [dbo].[event_look_up] et on da.Eventy_Type_Id = et.Event_Type_Id

    join

    (

    select Entry_ID, Case Event_Value when 'Enrollment Analyst' then 'Completed' else 'Pending' end as Status

    from

    (

    select Entry_ID, Event_Value, ROW_NUMBER() over(partition by Entry_ID order by Event_Time desc) as RowNum

    from dbo.tbl_doc_activity da

    inner join [dbo].[event_look_up] et

    on da.Eventy_Type_Id =

    et.Event_Type_Id

    ) x

    where x.RowNum = 1

    ) xyz on xyz.Entry_ID = da.Entry_ID

    select * from Status_of_Enrollment

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Thank you for spending your time on this!!!

Viewing 15 posts - 1 through 15 (of 19 total)

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