Creating an SCD Type 2 in T SQL without using MERGE

I am attempting to create an SCD type 2 using T-SQL without MERGE (I'm not allowed to use it as a condition of the development work I am doing). I can use a CTE, but I have not tried that yet.
I have a temp table that contains ten records that I am testing with. The following is one variant of the code I have used to try and make this work:
declare 
@System_User nchar(50)
,@CurrentDate datetime 
,@MaxCheckDate datetime
set @System_User = system_user
set @CurrentDate = getdate()
--INSERT
insert dim.slot
Source_Slot_ID
,Slot_Start_DateTime  
,Patients_PerSlot
,IsSlotSearchable
,IsSlotVisible
,[Created_Date]
,[Created_By]
select
src.IdSlot
,src.SlotDateTime
,src.PatientsPerSlot
,src.IsSlotSearchable
,src.IsSlotVisible
,@CurrentDate
,@System_User
from #TmepSlot src
left join dim.Slot dest
on src.IdSlot = dest.Source_Slot_ID
left join (select source_slot_id, max(created_date) as created_date from dim.slot group by Source_Slot_ID) MaxRecord
on dest.Source_Slot_ID = MaxRecord.Source_Slot_ID
and dest.Created_Date = MaxRecord.created_date
where dest.Source_Slot_ID is null
or
src.PatientsPerSlot
<> dest.Patients_PerSlot
or
src.IsSlotSearchable <> dest.IsSlotSearchable
or
src.IsSlotVisible
<> dest.IsSlotVisible
The problem with this variation is that when I change a value in the source like src.Patients_PerSlot, and then run the query, I get the new record i expect, but when I run the query again, a duplicate record gets created. 
How do I correctly isolate the correct latest record and add the changed record without inserting that changed record more than once?
Thank you for your help.
cdun2

Hi,
shouldn't you use an inner join between dest and maxrecord like so:
from #TmepSlot src
left join (dim.Slot dest
inner join (select source_slot_id, max(created_date) as created_date from dim.slot group by Source_Slot_ID) MaxRecord
on dest.Source_Slot_ID = MaxRecord.Source_Slot_ID
and dest.Created_Date = MaxRecord.created_date)
on src.IdSlot = dest.Source_Slot_ID
where dest.Source_Slot_ID is null
regards,
Rudolf
Rudolf Swiers
Thanks! I don't remember when I've done a join that way, but it makes sense.
cdun2

Similar Messages

  • How to create Users/Roles for ldap in weblogic without using admin console

    Is it possible to create Users/Roles for ldap in weblogic without using admin console? if possible what are the files i need to modify in DefaultDomain?
    or is there any ant script for creating USers/Roles?
    Regards,
    Raghu.
    Edited by: user9942600 on Jul 2, 2009 1:00 AM
    Edited by: user9942600 on Jul 2, 2009 1:58 AM

    Hi..
    You can use wlst or jmx to perform all security config etc.. same as if it were perfomred from the admin console..
    .e.g. wlst create user
    ..after connecting to admin server
    serverConfig()
    cd("/SecurityConfiguration/your_domain_name/Realms/myrealm/AuthenticationProviders/DefaultAuthenticator")
    cmo.createUser("userName","Password","UserDesc")
    ..for adding/configuring a role
    cd("/SecurityConfiguration/your_domain_name/Realms/myrealm/RoleMappers/XACMLRoleMapper")
    cmo.createRole('','roleName', 'userName')
    ...see the mbean docs for all the different attributes, operations etc..
    ..Mark.

  • How to create apple id for mac app store without using credit card and there is no any option for payment none. please tell how to download free apps from mac app store

    how to create apple id for mac app store without using credit card and there is no any option for payment none. please tell how to download free apps from mac app store

    my problem solve by me
    first create apple id
    fill credit card details
    and complete your account creating  process.
    than go to app store or itune store
    login your acount
    click right side  - account button
    than again login for account setting
    next go to payment information and click edit button
    when u enter payment infomation
    click none button in payment method and click done button.
    than ur credit card has been removed.
    but rs. 60 will deducted in your account when u doing this process.

  • Creating a SCD type 2

    Hi All,
    Can anyone tell me the procedure to do a SCD type 2 in ODI. Please list me the steps. I tried doing it myself but it seems to be not working. Especially the Sequence generator. The surrogate keys are not getting generated and nor the values getting updated. I tried to look for the solution or examples in the internet but without success.
    Thanks in advance

    For a better performance, you can use a Query transform before Table Comparison, use the primary key fields (that you use inside Table Comparison) in the Order By tab of the Query transform and select the option Sorted input in Table Comparison transform.

  • Create Or Replace Type How can I to use ?

    Hi
    Where can I to find examples using Type (create or replace type) and call in Procedure ?

    There is a wide range of requirements one can satisfy using Oracle's advance data types.
    The complexity of which differs from one to another - which means that no single set of examples can cover the whole spectrum of how these data types can be applied.
    Exactly what do you have in mind? Do you intend to use it in an object-relational design fashion? In a PL/SQL object-orientated fashion? Simply for dealing with issues like bulk processing? Etc.
    For example, how to construct an object of an advance data type can be as simple as calling the default constructor to being as complex as discussing how to implement inherantance constructors up the chain of parent classes (types) from which the current class has been subclassed from.
    If you can provide more details on your requirements, we will better be able to answer your questions.

  • How to create a App domain in sharepoint 2013 without using DNS Manger

    Can we create  AppDomain for Sharepoint Hosted App without using DNS Manager ? In short I have to create App Domain for my local sharepoint environment.

    You cannot create a APPdomain without DNS manager. 
    You can install DNS role on a machine and update your sharepoint server's DNS to consume from this DNS server. APPdomain cannot work without DNS

  • How to Create Webtemplate in SAP BI 7.0 without using PORTAL?

    Hi,
    I'm junior consultant sap BI ; I want to do a webtemplate in BI 7.0, but the firm doesn't have SAP Portal.
    I want to know if I can create my web template in BI 7.0, without using a portal? If I can do it, please tell me how!
    Thanks very much!
    Edited by: Gaudenzio on Jul 1, 2009 11:26 PM

    you will have to use WAD3.5 for that - you cannot use WAD 7.0 without having a JAVA Stack or the necessary JAVA Components installed in your app server.
    Then the question would be :
    Even if you do manage to create a WAD7.0 template without a JAVA Stack - you cannot run the same since it required portal...???

  • Dynamic SQL without using SQL

    I have a variable that contains a formula, eg.
    V_FORMULA varchar2(200) := '5 * 50 + 200';
    I want to assign the result of the formula into another variable, without using a DB call with SQL.
    eg.
    V_RESULT number;
    V_RESULT := DBMS_surprise_package(V_FORMULA);
    I want V_RESULT to be 450 after the statement is executed.
    Is that possible?? Is there such a package in PLSQL?
    I think the Forms NAME_IN package did something similar.

    970779 wrote:
    I guess I'll just have to rewrite it using execute immediate with bind variables to stop the shared pool getting filled up with thousands of these statements, since none of you have a non-db solution.Write your own if the expressions are simple enough...
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    l_formula varchar2(200) := '5 * 50 + 200';
      3    l_result  number := 0;
      4    tok       varchar2(100);
      5    op        varchar2(100);
      6    function get_token(str in out varchar2) return varchar2 is
      7    begin
      8      tok := trim(regexp_substr(str,'^[0-9]+|[^0-9]+'));
      9      str := trim(regexp_replace(str,'^([0-9]+|[^0-9]+)'));
    10      return tok;
    11    end;
    12  begin
    13    loop
    14      tok := get_token(l_formula);
    15      exit when tok is null;
    16      if tok in ('*','+','-','/') then
    17        op := tok;
    18      else
    19        case op when '*' then l_result := l_result * to_number(tok);
    20                when '+' then l_result := l_result + to_number(tok);
    21                when '-' then l_result := l_result - to_number(tok);
    22                when '/' then l_result := l_result / to_number(tok);
    23        else l_result := to_number(tok);
    24        end case;
    25      end if;
    26    end loop;
    27    dbms_output.put_line(l_result);
    28* end;
    SQL> /
    450
    PL/SQL procedure successfully completed.:D

  • Can I create a dynamic report in the server without using a report template

    Hi,
    My company just bought a Crystal Report Server XI and it didn't have a report designer.
    I can't start creating report without the designer.
    The question is can  I generate a dynamic report at runtime (on the crystal report server ) without using report template?
    My project requirement is to use a crystal report server to manage the reports.
    Some client web application will just access this report server.
    I  hope the experts can provide me some guidance.
    regards,
    Rulix
    Edited by: Rulix Batistil on Nov 3, 2008 8:08 AM

    Hi Rulix,
    The latest version of CR Server is 2008. Therefore I'm assuming you are using CR Server 2008.
    New in CR 2008 is the .NET report modification software development kit (SDK). The report application server (RAS) SDK is now available for users of Crystal Reports .NET API without the use of a RAS server. Report modification such as changing, adding, or removing database providers, or adding, removing, or creating report objects, parameters, formulas, and sections can be achieved by accessing the RAS SDK through the Crystal Reports .NET SDK.
    Java developers however receive the JRC and Java SDK documentation through the free Crystal Reports for Eclipse download. This product will be updated on a separate schedule from Crystal Reports.
    Further Information and samples are available in our [Developer Library|https://www.sdn.sap.com/irj/sdn/businessobjects?rid=/webcontent/uuid/5001d5de-f867-2b10-00bf-8d27683c85a0]
    Kind regards,
    Tim

  • Create a new row in a table without using add new row button

    I want to add a new row to the table without using the add new row button of the table. I'm not able to display default row in the table. Though if click on apply the record appears after saving in the database. Any thoughts how to implement this functionality.

    Here is what you have to do.
    1) You have to handle this in processRequest()
    2) In the AM code , u need to check if there is already a row exisit or vo is blank
    if (vo.getFetchedRowCount() == 0)
    // first time
    vo.setMaxFetchSize(0); // THIS IS REQUIRED.
    Row row = vo.createRow();
    vo.insertRow(row);
    row.setNewRowState(Row.STATUS_INITIALIZED);
    else
    //If already rows are there then you suppose to insert in the end
    // i assume you would have execute your vo
    YourVORowImpl row= (YourVORowImpl)vo.getRowAtRangeIndex(0);
    vo2.insertRowAtRangeIndex();
    It should work.

  • Bolding all type before en space without using nested styles

    I'm trying to have all the words before an en space in all paragraphs made boldface without using nested styles. The nested styles work great for print, but don't seem to do the trick for epubs, such as this project.
    For example:
    Car Ferrari GTO
    I tried doing a find/change for all the text formatted with the nested style, changing the nested style to no char. style + Bold. But for some reason the nested style stays attached, and if I delete the character style that is called for in the nested style, the text loses its bf.
    Thanks for any help!!

    Silly me -- that trick uses another sort of workaround.
    I meant to point you to Harbs' script ApplyNestedStyles: http://in-tools.com/indesign/scripts/freeware/ApplyNestedStyles.zip

  • How do I create a summary sheet of Group values without using a subreport?

    Hello,
    I have a report (CR 2011 over MySQL) that churns through a lot of data. It presents information in the Details section and the Group Footer section. I want to include a summary sheet as the first page that only shows the Group Footer data. The only way I've figured out how to accomplish this is by putting the same report as a subreport into the Report Header and then suppressing the details section. I don't like this approach because the same data-intensive report is actually running twice now.
    I can't just use the "Hide" feature in the Details Section because when I run the report (from the .NET viewer) none of the details print. To print the details I would have to double-click on each Group Footer which launches a new tab with the details for that particular group only.
    I know how to create shared variables so not sure if that can play a part.
    Thanks in advance for tips in keeping this to one report with a summary page!
    Mark

    Hi Mark,
    What kind of summary functions do you use on the Group Footer? As long as they're basic summaries (no print time functions etc), you could just move them to the Group Header. The Group header can then serve as your 'Summary sheet'.
    If these are printime functions that you're dealing with, then there isn't another way other than using a Subreport to show the Summary sheet. The Subreport itself does not need to be against the same dataset though.
    To speed it up, you could perhaps, create a Stored proc that does all the Summarization and use those columns on the report.
    -Abhilash

  • Create Planning Application for the first time without using workspace

    hi,all:
    I come across a problem:The Hyperion Planning Application isn't configured into the workspace,but i have to create a Hyperion Planning Application for the first time.So, have any other methods to solve this problem? Can I use other tools or something to create it?
    thanks very much

    yellow wrote:
    Hi,John,Thanks for your quick reply.
    I think after install Hyperion Planning,at first time can't create application in this address:http://localhost:8300/HyperionPlanning/ ,usually create it in workspace.
    Is the address you said different from http://localhost:8300/HyperionPlanning/?
    thanksI gave you the address to create a planning application directly - http://localhost:8300/HyperionPlanning/AppWizard.jsp
    Notice the AppWizard.jsp on the end.
    If it version 11 you will be able to create your datasource from that location, if it is version 9 then you will have to create a datasource first from the configuration utility.
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • Can I create a smart playlist on my iPhone without using iTunes first?

    I often find myself on my iPhone, away from my computer, wanting to further refine the currently playing smarlist, say only play tracks with three stars or more. It would be nice to have this, or just iTunes DJ (iPhone DJ?) on my iPhone, with an option to play higher rated songs more often.

    SERIOUSLY!!!  I was pretty shocked when I realized iTunes DJ isn't on my iPhone.  It seems like it should be, seeing as 1) it's one of the main perks/rewards of going through the hassle of rating all your songs, and 2) for many people (including myself) most music listening time is spent on their iDevices (listening in the car, at work, etc.).  So the fact that it's not there to be utilized is pretty weird and slightly upsetting.  Also the DJ mix should sync between iDevice and computer so you can continue listening to the same list going to and from home.

  • SCCM 2012 Endpoint applies two policies "Default Policy & Custom policy" without using merge

    Hi All,
    Am facing an issue deploying endpoint policies @ the configuration manager, as for some device collection it applies the default policy without being deployed or merged with any other policy.
    below is snapshot from policies on SCCM & policies applied on one of the clients.
    Thanks

    That's default behavior. The default policy will always be aplied without the need to be specifically deployed. If you look at the applied settings you should see that the settings are merged were applicable. See for a nice explanation:
    http://blogs.technet.com/b/mspfe/archive/2013/11/13/system-center-configuration-manager-2012-scep-policy-behavior.aspx
    My Blog: http://www.petervanderwoude.nl/
    Follow me on twitter: pvanderwoude

Maybe you are looking for

  • Air Repair - Parts Used?

    Had a hardware problem with my Gen 1 Air. The only problem was that the internal microphone was dead. Took it to Apple store and it was sent to Houston for repair. Got it back....all working fine now. Noticed on the packing slip a list of parts used

  • Looking for training material

    Does anyone have any training material that can teach power user how to create Query? Power Point is the best. Please send it to [email protected] I will definitely reward points for your knowledge sharing!

  • Overly large time machine files

    Hi There, my disk that I use for Time machine (120GB Lacie USB) has recently become corrupted, so that it is currently 'read only' So I decided to copy my Time machine files to another drive, so I could format my main one, and then put them back. But

  • Flash preloader not showing

    Hi, I have an odd problem, I've used a very basic preloader for my Flash file (CS5) it works as expected in Flash Test using the simulated download feature but when I upload everything to the remote server, the preloader doesn't show, there is a dela

  • Problems Displaying data from RFC on Adobe Forms

    Hi, I have some Problems with creating an Adobe Form and hope, someone can help me or give me some hinds to some tutorials, which can help me. I'm developing an webdynpro-application which get data from a R/3 via RFC-Call. Context-Binding and so on i