Calculate the % of Cases

Hi,
I have a table as below
caseid  companyname datecreated
1              abc                 2012/01/01
2             abc                  2012/01/02
3             xyz                   2012/04/03
i want a query which gives me the number of cases, capmany wise and the percentage as well
O/p
abc 2  (2/3)
xyz  1  (1/3)

No need CTE :-)
Select  DISTINCT companyname,1.0*COUNT(companyname)Over(partition by Companyname) /COUNT(companyname)over()  From company
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence

Similar Messages

  • How to calculate the total of absences? How to collect data from a specific line of a table?

    Hi,
    Again, I made a nice coloured picture from a screen capture which summarise the improvements that I would like to make in my form,
    Situation:
    For an educational purpose, I made this form   to simplify the way of recording the data and also to develope the independence of the students.
    ( I am doing this on a voluntary basis, working extra hours on my free time but I don't really mind because I am learning a lot of things in the same time)
    After being tested by the teacher, the student has to record the short date, the lines memorised, his grade, number of mistakes, and his attendance.
    I created everything in Word, then converted the file in PDF, then I created all the different fields with Adobe acrobat.
    There is in total 4 sheets, there are all similar except the first one in which there is a box with: date started, date finished, total time spent, absences.
    Below this box there is a table with 16 lines from (A to P) and 7 columns (Days, Date, From.. to.. , Grade, No. lines memorised, No. Errors, Attendance) ( so this table is present on all the sheets)
    Due to the fact that some students need more time than others, and also beacause some text need more time, I estimated a need of 4 sheets at the very most.
    I would like to make the following amelioration and automate the inputting of some of the data because I know that some of the students will certainly forget, so to avoid this scenario I am trying to make this form the easiest possible.
    screen capture of the form:
    screen capture of the form editing, you can see the names of the different fields:
    here is the form (only the first page) : http://cjoint.com/12fe/BBotMMgfYIy_memorisation_sheet_sample.pdf
    In  yellow 00000:
    At present, the students has to input the total of absences manually, is there a way ( script) to automate this by initialising the field next to "Absences" at  " 0 day"   and then everytime that Absent is selected from the COMBO BOX, it add 1 and it is displayed like this:  " 1 day" then " 2 days"  then " 3 days" etc … (so from what I read I have to initialise a counter a the beginning and then for (i...   ) count= count++; something like this...
    Furthermore, I need a solution to overcome the possibility that a second sheet may be needed for the same student; therefore I would need the data from the "attendance column" from the second sheet ( and perhaps the 3rd and 4th aswell) to be added on the "absences field" in the first sheet
    My idea: everytime that the short date is inputted in the first line (next to A) in the "Date" column of one of the 4 sheets then we check the 16 Combo box of the attendance column in this sheet instead to check 16*4=64 fields fot the 4 sheets in one go?
    but I don't know at all how to write it in Javascript. Or perhaps there is a way more easier than that?
    Shall I allocate a value for Absent on the “ export value”?
    In purple
    At present I wrote a simple script which matches the number of lines to the poem selected (Eg.  if I select the poem V.Hugo,  the number "36" will appear next to Number of lines).
    Again I would like the make the life of the students very easy so I would like a script which detects this number “36” on the "From .. to …" column,  as soon it is detected (on the first sheet or 2nd or 3rd or 4th)  check from the same line if "A / Pass" or "B / Pass" have been selected in the "Grade" column ,if yes the short date inputted on this line will be written on the field next to "Date finished" .
    this is a simple example with 36 lines only but somethimes, the students may have to memorise 80 lines and more, this is the reason for having 4 sheets in total.
    So basically I would like to automate the field next to" Date finished:" with a script that collect the short date from the day in which the student has finished his memorisation with "A / Pass" or "B / Pass"
    As for the "Total time spent" George Johnson helped me with a script that calculate the difference betwen date started and date finished (thank you)
    I am sollicting your help, because after trying for hours I was really confused with the different if/else needed. And in top of that, it’s my first experience with Javascript.
    I anticipate your assistance, thanking you in advance.

    I found this for counting the absences, its give you the total that's perfect, but is there a better methode which avoid me to write all the fields name, more simple????
    ( I found the idea here : Re: Total number added automatically  )
    // custom calculation script for field "Total #"
    function CountFields(aFields) {
    var nFields = 0;
    for(i = 0; i < aFields.length; i++) {
    try {
    // count null values, export value of Absence is 0;
    if(this.getField(aFields[i]).value == "0") nFields++;
    } catch(e) {
    if(e['message'] == "this.getField(aFields[i]) has no properties") app.alert("unknown field name: " + aFields[i]);
    else app.alert(e.toString());
    } // end catch
    } // end for aFields
    return nFields;
    // create array of field names to count
    var aNames = new Array("Sheet1AttendanceA","Sheet1AttendanceB","Sheet1AttendanceC","Sheet1AttendanceD","Sh eet1AttendanceE","Sheet1AttendanceF",
    "Sheet1AttendanceG","Sheet1AttendanceH","Sheet1AttendanceI","Sheet1AttendanceJ","Sheet1Att endanceK","Sheet1AttendanceL",
    "Sheet1AttendanceM","Sheet1AttendanceN","Sheet1AttendanceO","Sheet1AttendanceP" );
    // count the non-null fields;
    event.value = CountFields(aNames);
    As for the 2nd question, I've tried to do something similar to the previous script, but of course it doesn't work, but I am quite sure that the idea is similar:
    I don't know also how to add the other condition: the student should get A / Pass or B / Pass in order to consider he has finished??? and also how to check these condition from page 2, 3 and 4 and collect the date
    function Datefinished(bFields) {
    d2.value = nFields[i].value;
    for(i = 0; i < aFields.length; i++) {
    try {
    if(this.getField(aFields[i]).value == this.getField("NumberLines").value) d2.value = nFields[i].value;
    } catch(e) {
    if(e['message'] == "this.getField(aFields[i]) has no properties") app.alert("unknown field name: " + aFields[i]);
    else app.alert(e.toString());
    } // end catch
    } // end for aFields
    return nFields;
    // create array of field names to check
    var aNames = new Array("Texte00","Texte54","Texte56","Texte58","Texte60","Texte62","Texte64","Texte66","Te xte68","Texte70","Texte72","Texte74","Texte76","Texte78","Texte80","Texte82");
    var bNames = new Array("d1","d3","d4","d5","d6","d7","d8","d9","d10","d11","d12","d13","d14 ","d15","d16","d17");   // d1 is included because in some cases a student can finish in 1 day (short text);

  • How to calculate the unit for RATE?

    Hey All,
    I am not sure if there is something standard for this or not.
    I am calculating the 'Rate' by using 'Value/Amount' and 'Quantity' as follows -
    Rate == Value /  Quantity
    I need to calculate the unit for the rate as below -
    Rate unit == Value unit (Currency) /  Quantity unit (Base_uom) 
    (for example -
    if value is 1000 USD and quantity is 10 TO then Rate should come out as 100 USD / TO)
    Could anyone please suggest how to calculate the unit in this case?
    Many Thanks!
    Tanu

    Hi,
    Go through the below link it may give some idea
    http://help.sap.com/saphelp_nw04/Helpdata/EN/19/1d7abc80ca4817a72009998cdeebe0/content.htm
    Regards,
    Marasa.

  • How to calculate the total of bytes transferred when I submit a PDF Form in A. Reader

    Hello,
    I need to know some way for calculate the total of bytes transferred when I submit a PDF form using JavaScript, hereby:
    b ******************************************************************
    i var service_url = http://some_webservice/;
    i var send_type = "PDF";
    i var doc = event.target;
    i doc.submitForm( { cURL: service_url, cSubmitAs: send_type } );
    b ******************************************************************
    b The reason:
    I need to indicate the percentage of bytes sent to the server, in real time. Adobe Acrobat shows a progress bar and the transferred quantity in bytes, but Adobe Reader doesn't. Is in this case, when I need to find a way in order to make something similar.
    b Than you for your time.

    You can use SharePoint Designer and calculate the total in xslt view. Refer to the following post for more information
    http://community.bamboosolutions.com/blogs/bambooteamblog/archive/2009/04/24/how-to-total-calculated-columns-in-a-sharepoint-list.aspx
    http://blog.metrostarsystems.com/2012/12/03/jennys-sharepoint-tip-sum-calculated-columns/
    Cheers,

  • How to calculate the total  length of a Line

    Hi,
    We are using Mapviewer for representing for spatial data in form of a Image .
    We are using Mapviwer.addLinearFeaure for drawing lines on the Image( browser)
    Thsese lines are drawn .
    Now our requirement is we need to calculate the length of the lines in our Image .Please tell me how to do this .
    Thanks in advance
    Edited by: user672373773 on Nov 11, 2009 9:11 AM

    You can do this by two ways.
    1) create SDO_GEOMETRY from your coordinates and use SDO_GEOM.SDO_LENGTH to get length of the line.
    Or
    2) iterate your line points coordinate array and calculate distance between points add it to final length.
    Here is snippet to calculate length of line (not tested)
    length = 0;
    for( i=0; i<coordpts.length-2; i++) {
    length = length + getDistance(coordpts[0], coordpts[1]);
    to calculate distance between 2 points use below code (getDistance() source code)
    double dblDistance = Math.sqrt(Math.pow((dblPt2[0] - dblPt1[0]), 2) + Math.pow((dblPt2[1] - dblPt1[1]), 2));
    In both case you need to convert screen coordinate to map coordinate.
    Sujnan

  • Biased Hall effect sensor and NI 9201 module. How can I calculate the velocity of an object?

    For my final year project at university I have designed and built a drop tower for testing the energy dissipation performance of test pieces.
    In the system I specified having a biased Hall effect sensor (gear tooth sensor) to calculate the speed of the impactor by having a serrated target (ferritic) moving past it.
    The idea behind having a serrated target was to enable an average of several readings of time period to be taken, then to use this to divide the known length of the serrations to calculate speed.
    The problem I am having is when using the time period measuring block in LV it only wants to measure the period of the first wave, is there any way I could get LV to measure all four periods (there are four serrations) and average them?
    Here is an image of the target incase what I have said was a little confusing: http://tinypic.com/r/2a0b8ck/6
    Any help will be greatly appreciated!

    1. The NI 9201 has only analog inputs, so you have no other choices with that devices.  I did not look it up before my earlier response.  Something about the wording of your first post made me think you were measuring the period with a counter.
    2. I am not sure which "time period measuring block" you are using.  Please post your VI.  Before you post it, run it with your Hall sensor so that you have some data recorded.  Go to the Edit menu and choose Make Current Values Default."  Save the VI.  The indicators on your VI will then have your data saved.  Post that VI.
    3. I am assuming that you will get a signal which looks something like this, although not necessarily starting exactl at zero time or having exactly uniform spacing between the pulses.
    Using some simple logic you can determine the time of the transitions between high and low.  The differences between the times of successive transitions are your periods.  For the image above the falling edges (going from +1 to -1) occur at about 64, 192, 320, and 448.  The differences are 128 in each case.  For your impact data the differences are likely to not all be the same as yout target decelerates.
    After I see you VI, I can give some suggestions about how to proceed to calculate the differences.
    Lynn

  • How to calculate the Percentage differencebased on two values

    Not sure how to do this.
    Just want to calculate the % difference of two values (seem to have a problem when one value is zero)
    Here is the current output
    49 Apr 2
    64 Aug 1
    55 Feb 0
    Here is the output I would like to see
    49 Apr 2 4.08%
    64 Aug 1 1.56%
    55 Feb 0 0.00%
    Here is the current SQL
    Select TO_CHAR (RCA_CLOSE_DATE, 'Month') "Month",
    SUM (CASE WHEN RCA_CODE = 'BI&D' THEN 1 ELSE 0 END) "BI&D - CBAT No of Adj",
    Count(1) as "Count of Adjustments"
    from TW_BILL_ADJ_DATA
    where (RCA_CLOSE_DATE between nvl (:P8_DATE_FROM,FORM_RECEIVED)
    and nvl (:P8_DATE_TO, FORM_RECEIVED))
    group by TO_CHAR (RCA_CLOSE_DATE, 'Month')

    You can try something like this one:
    Select TO_CHAR (RCA_CLOSE_DATE, 'Month') "Month",
    SUM (CASE WHEN RCA_CODE = 'BI&D' THEN 1 ELSE 0 END) "BI&D - CBAT No of Adj",
    Count(1) as "Count of Adjustments",
    round(count(1)/SUM(CASE WHEN RCA_CODE = 'BI&D' THEN 1 ELSE 0 END) * 100,2) || '%' percent
    from TW_BILL_ADJ_DATA
    where (RCA_CLOSE_DATE between nvl (:P8_DATE_FROM,FORM_RECEIVED)
    and nvl (:P8_DATE_TO, FORM_RECEIVED))
    group by TO_CHAR (RCA_CLOSE_DATE, 'Month')
    CODE NOT TESTED !!!
    Best Regards
    Krystian Zieja / mob

  • How to calculate the size of web forms in hyperion planning?

    Hi Experts,
    I am trying to calculate the size of planning forms in Hyperion smart view., but i am unable to find out the way to calculate.
    Can you pls explain how to calculate the size of web form in Smart view?
    --- Srini.

    Hi Srini,
    First, here is what Oracle says:
    Data Form Size Estimation:
    To get a rough estimate of data form size, open the data form and select File > Save As from the browser. The size of the .HTML file is the portion of the data form that changes based on grid size. The .JS files remain the same size and can be cached, depending on browser settings. Information such as data form definitions, pages, and .gif files are not compressed when data forms are opened and sent to the Web browser.
    I have not been able to find out using their method.
    In any case, you can find out the size of grid by using below
    1. Right click on the form grid and click "View source"
    2. Save the source file as "Example.html"
    3. Right click the saved file and click "Properties"
    4. The Form size whould be same as that of file..
    Let me know if it helps.
    Cheers
    RS

  • In labview,how to calculate the parameters of the bilinear model that simulates the generation electroencephalogram?

    Dear Sir or madam:
    I have collected a lot of electroencephalogram data, which looks like a continuous sine wave plus a noise signal. what i want to do now is to fit the data with the bilinear model as the attached jpg file. the problem is the parameters of the model are changing with the evolution of the signal. would someone like to tell me how to calculate the parameters in the bilinear model?
    thank you very much
    Attachments:
    Bilinear_Model.jpg ‏33 KB

    I can point you in the right direction, but probably not answer your question really well. If you have the pro or full distribution of LabVIEW, you can use the curve fitting VIs to match any set of data to a theoretical curve. The curve fitting Express VI may do all you need to do (use the nonlinear option). To get the signal evolution, break your data into pieces and process each. If you need to average a bit, you can use a sliding window of your data for each analysis, moving the window less than the window width for each analysis.
    There are a plethora of curve fitting techniques built into LabVIEW - matrix operations, linear and log linear fits, Levenberg-Marquardt methods, downhill simplex, etc. You will probably need to experiment a bit to get a stable
    algorithm for your case. Check your literature for ways other people have done this. There may be an easy, stable method out there.
    If you are unfamiliar with curve fitting techniques, or you do not have the pro or full versions of LabVIEW, I would recommend "Numercial Recipes in C" by Press et. al., published by Cambridge University Press. The chapter on Modeling of Data will get you going. The rest of the book will provide any background you need.
    This was a very general answer. If you need something more specific, let me know. Be aware that this type of problem usually requires some trial and error to get right. The answers should be tightly scrutinized before being believed.
    This account is no longer active. Contact ShadesOfGray for current posts and information.

  • How to calculate the total from users input in switch?

    I dont know how to hold the input from user. But here is part of my coding :
    System.out.println ("Type 1 for buying Ruler"+
    "\nType 2 for buying Pencil");
    stationaries = console.nextInt();
    switch (stationaries)
    case 1 : System.out.println("Ruler per unit : MYR1");
    System.out.println("How much does you want? : ")
    wantRuler = console.nextInt();
    sum = wantRuler * 1;
    break;
    case 2 : System.out.println("Pencil per unit : MYR2");
    System.out.println("How much does you want? : ")
    wantPencil = console.nextInt();
    sum = wantPencil * 2;
    break;
    How can I calculate the total for both of the stationaries if user wants 5 for ruler and 6 for pencil?

    Note: This thread was originally posted in the [Java Programming|http://forums.sun.com/forum.jspa?forumID=31] forum, but moved to this forum for closer topic alignment.
    Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.

  • How system calculate the required qty. after MRP RUN

    Hi,
    I want to know if we are using MRP Type as PD and also we are calculating automatic saftey stock and re order point qty. after MRP RUN according to which rule formula system calculate the safty stock, reorder point qty. and the required qty. as a PR.
    and if we are not using calculate safety stock automatically and if we set safety stock qty. manually in this case how system will calculate the required qty.
    regards,
    zafar

    please check the below links.
    http://help.sap.com/erp2005_ehp_04/helpdata/EN/6f/b441a9a1b011d3a82d0000e82a3c24/content.htm\
    http://help.sap.com/erp2005_ehp_04/helpdata/EN/f4/7d256344af11d182b40000e829fbfe/content.htm
    http://help.sap.com/erp2005_ehp_04/helpdata/EN/ff/515c4749d811d182b80000e829fbfe/content.htm
    please check the above links may get some idea.
    Regards,

  • Function module which could calculate the previous month's start date.....

    hi,
    I want a function module which could calculate the previous month's start date and end date...
    Say todays date is  like 29.05.2007(start date) it should return
    01.04.2007 and 30.04.2007...
    IS there any FM for this ... or how to go about this scenario ???
    thanks in advance
    samm

    See the below Logic :
    DATA :g_date(2) TYPE n,           " Date
          g_month(2) TYPE n,          " Month
          g_year(4) TYPE n ,          " Year
          g_bill_low(10) TYPE n,       " From date
          g_bill_high(10) TYPE n,      " To date
          g_month1(2) TYPE n,         " Month
          g_year1(4) TYPE n,          " Year
          g_date1(2) TYPE n,          " Date
          g_year2(4) TYPE n,          " Year
          g_datum LIKE sy-datum.      " System date
    RANGES : r_bdate  FOR vbrk-fkdat.             " Billing date
      g_datum = p_date + 10.
      g_month = g_datum+4(2).
      g_year = g_datum+0(4).
      IF g_month = 1.
        g_year = g_year - 1.
        g_month = 12.
        g_date = 1.
      ELSE.
        g_month = g_month - 1.
        g_date = 1.
      ENDIF.
    Passing the date to billing date-low
      CONCATENATE  g_year g_month g_date  INTO g_bill_low.
      r_bdate-low = g_bill_low.
      r_bdate-sign = 'I'.
      r_bdate-option = 'BT'.
      g_month1 = g_datum+4(2).
      g_year1 = g_datum+0(4).
      IF g_month1 = 1.
        g_year1 = g_year1 - 1.
        g_month1 = 12.
      ELSE.
        g_month1 = g_month1 - 1.
      ENDIF.
      CASE g_month1.
        WHEN 1.g_date1 = '31'.
        WHEN 3.g_date1 = '31'.
        WHEN 4.g_date1 = '30'.
        WHEN 5.g_date1 =  '31'.
        WHEN 6.g_date1 = '30'.
        WHEN 7.g_date1 = '31'.
        WHEN 8.g_date1 = '31'.
        WHEN 9.g_date1 = '30'.
        WHEN 10.g_date1 = '31'.
        WHEN 11.g_date1 = '30'.
        WHEN 12.g_date1 = '31'.
      ENDCASE.
      g_year2 = g_year1.
      IF g_month1 = 2.
        g_year2 = g_year2 MOD 4 .
        IF g_year2 = 0.
          g_date1 = 29.
        ELSE.
          g_date1 = 28.
        ENDIF.
      ENDIF.
    Passing the date to billing date-high
      CONCATENATE  g_year1  g_month1  g_date1 INTO g_bill_high.
      r_bdate-high = g_bill_high.
      APPEND r_bdate.
    Reward Points if it is helpful
    Thanks
    Seshu

  • Calculate the date diff

    Hi, The requirement is to calculate the diff between 2 date fields and display it. I could able to get the difference between the 2 date fields. But now the result column SHOULD DISPLAY the result ONLY if the 2 date fields have the date set ELSE it should be left blank(basically NULL shud be set to the result column in such cases).
    The formula which I have used to get the result is :
    (NOERR(date1)<>0 AND NOERR(date2)<>0)*(date1-date2).
    The above formula works fine and gives the result as desired except that it puts "0" even though the date fields doenst have a value.I have tried to use the ELSE part by giving "1/0" thinking it wud give me "#" but this didnt help me out anyway.
    Any inputs on this...

    Thanks for the response.
    That was an option which I also thought of and I wud use it only as a last rescue and trying if I can get some info to do it otherwise.
    The other option which I have in my mind is to just get this diff into the cube and this shud resolve but then again I hv to chg the BW structures and unnecessarily I wud be increasing the load to the cube.
    Any other option in Bex ...???

  • In Report I have a 2D axis system. How do I properly calculate the grid line interval for exactly 10 dots per tick

    Having trouble getting the dots to line up correctly with the ticks of a 2D axis.  I would like to have exactly 10 dots per tick.  The programming is no problem.  I set the D2AxisGridInterv variable after opening the 2D axis object.  I can't seem to figure out how to calculate the number that results in exactly 10 dots per tick.  I also have tried manually iterating to get 10 dots and have not been succesful.  What is this number based from?  It says as a percentage of the diagonal of the worksheet.  I can get pretty close to 10 dots per tick, but it is always off just a bit.  Is there really a way to get scientific based dots on a 2D axis so that the data can be analyzed from a printed plot?
    Thanks-Ryan

    Hi Ryan,
    I'm not entirely sure what you mean by "dots", but I'm going to guess you meant grid lines set to dot display.  In that case you can align the grid lines to the axis sub-ticks, then set the sub-ticks to invisible.  The sub-ticks can be set to N of them per axis tick.  Attached you will find an example of 10 dotted vertical grid lines per X axis tick.
    Let me know if you meant something else,
    Brad Turpin
    DIAdem Product Support Engineer
    National Instruments
    Attachments:
    Ryan37.zip ‏30 KB

  • How do i calculate the dates in this scenario

    I have a situation here and i am not able to think through it
    there are 4 date columns in a table and i need to do something like below
    First Record start date is the start date, and end date is the next start date -1
    Next start date is next start date, and end date is the first end date of the record set of the end dates
    Next start date pervious end date + 1 and end date is the current end date
    Next start date is the current date and next end date is the current end date
    for example lets say we have a table like below
    CustomerID CustomerType CustomerEffDt   CustomerTrmDt CustNationalBgnDt CustNationalEndDt
    1                  National           2013-08-05        9999-12-31      
    2010-11-08            2011-11-02
    Now my question is, we would have to calculate the customer effective start and begin dates and national begin and end dates based on the above criteria
    we would have to create 4 rows based on the above scenario
    I am going mad and not able to think through this
    Can somebody help me
    Thanks

    Declare @Example table (CustomerID int, CustomerEffDt date, CustomerTrmDt date, CustNationalBgnDt date, CustNationalEndDt date, otherstuff varchar(99))
    insert @Example Select 1, '3/19/2014', '9999-12-31', '3/19/2015', '2/19/2016', 'first'
    UNION Select 2, '3/19/2014', '9999-12-31', '4/19/2014', '5/28/2014', 'second'
    UNION Select 3, '2013-08-05', '9999-12-31', '2010-11-08', '2011-11-02', 'first example by OP'
    Select CustomerID,Num
    , case When Num = 1 Then '1/1/1900'
    when NUM = 2 then CustNationalBgnDt
    when NUM = 3 then DateAdd(day, 1, CustNationalEndDt )
    when NUM = 4 then CustomerEffDt End as startdate
    , case When NUM = 1 then DateAdd(day, -1, CustNationalBgnDt)
    when NUM = 2 then CustNationalEndDt
    when NUM = 3 then Dateadd(Day, -1, CustomerEffDt)
    when NUM = 4 then CustomerTrmDt End as EndDate
    From @EXAMPLE
    Cross Apply (Select 1 as Num UNION Select 2 UNION Select 3 UNION Select 4) as Numbers
    order by CustomerID, Num
    /* --Your result
    1 1 1900-01-01 2015-03-18
    1 2 2015-03-19 2016-02-19
    1 3 2016-02-20 2014-03-18
    1 4 2014-03-19 9999-12-31
    2 1 1900-01-01 2014-04-18
    2 2 2014-04-19 2014-05-28
    2 3 2014-05-29 2014-03-18 ---***
    2 4 2014-03-19 9999-12-31 --****
    3 1 1900-01-01 2010-11-07
    3 2 2010-11-08 2011-11-02
    3 3 2011-11-03 2013-08-04
    3 4 2013-08-05 9999-12-31
    CustomerID StartDate EndDate
    1 1900-01-01 2014-03-18
    1 2014-03-19 2015-03-18
    1 2015-03-19 2016-02-19
    1 2016-02-20 9999-12-31
    2 1900-01-01 2014-03-18
    2 2014-03-19 2014-04-18
    2 2014-04-19 2014-05-28
    2 2014-05-29 9999-12-31
    3 1900-01-01 2010-11-07
    3 2010-11-08 2011-11-02
    3 2011-11-03 2013-08-04
    3 2013-08-05 9999-12-31
    ;with mycte as
    select CustomerID, dt,col,row_number() Over(partition by CustomerID Order by dt) rn
    ,row_number() Over(partition by CustomerID Order by dt DESC) rn2 from @Example
    cross apply (
    values( CustomerEffDt,'CustomerEffDt'), (CustomerTrmDt,'CustomerTrmDt')
    , (CustNationalBgnDt,'CustNationalBgnDt'), (CustNationalEndDt,'CustNationalEndDt'))
    d(dt,col)
    Select m1.CustomerID,
    Case when m1.rn=1 Then '1/1/1900'
    When m2.col='CustNationalEndDt' Then dateadd(day,1,m2.dt)
    Else m2.dt end as StartDate,
    Case
    when m1.rn2=1 Then m1.dt
    When m1.col='CustNationalEndDt' Then m1.dt
    else dateadd(day,-1,m1.dt) End
    as EndDate
    From mycte m1 LEFT Join mycte m2 on m1.CustomerID=m2.CustomerID AND m1.rn=m2.rn+1
    Order by m1.CustomerID, m1.dt

Maybe you are looking for