SQL Subquery Help

Hi All ,
I have one scnario like following ...
i have some records .  So i want ids
SID     SNO     S.No2
            123        1
 1        321         4
           789         8
           456         9
          456         0
         789          2
  2     456          7
         741          3
         452          5
         789         3
         458         5
 3     784          4
        745          9
        852         0
        852         1
In Above 3 cases Consider the  SNO2  numbers...  
            SId  (1) have  some different no combination of S.No2.  
            SId (2) have   some different no combinations of S.No2.
    But  SId (3) have  Both the combination of  SId(1)  and  SId(2)
I need  SId no  like 3   which have the combinations 
Is there any  SQL Select Query ....  ?  Plese help me on this...
Thanks,
Sri

Hi All ,
I have one scnario like following ...
i have some records .  So i want ids
SID     SNO     S.No2
            123        1
 1        321         4
           789         8
           456         9
          456         0
         789          2
  2     456          7
         741          3
         452          5
         789         3
         458         5
 3     784          4
        745          9
        852         0
        852         1
In Above 3 cases Consider the  SNO2  numbers...  
            SId  (1) have  some different no combination of S.No2.  
            SId (2) have   some different no combinations of S.No2.
    But  SId (3) have  Both the combination of  SId(1)  and  SId(2)
I need  SId no  like 3   which have the combinations 
Is there any  SQL Select Query ....  ?  Plese help me on this...
Thanks,
Sri

Similar Messages

  • Bind variables in custom sql subquery

    Is it possible to use bind variables in a custom sql subquery? I have a top level query built with expressions and I am using the builder.subQuery() method to execute the report query containing the custom sql.
    Thanks,
    Will

    Yes, that should be possible. Here is what to do. Make your SQL string. Where you want to bind variables, use a question mark.
    example: select empId from employee where employeeId=?
    Then you want to create a Call object. Then you can do ReportQuery rq = new ReadAllQuery (sqlCall);
    here is how to bind:
    queryParams is a Collection
    //start code
    Call sqlCall = new SQLCall();
    ((SQLCall)sqlCall).setSQLString(sqlString);
    if ((queryParams != null) && (queryParams.size() > 0)) {
         Vector sqlParameterTypes = new Vector(queryParams.size());
         Vector sqlParameters = new Vector(queryParams.size());
         Iterator iter = queryParams.iterator();
         while (iter.hasNext()) {
              Object queryParameter = iter.next();
              sqlParameterTypes.add(SQLCall.IN);
              sqlParameters.add(queryParameter);
         ((SQLCall)sqlCall).setParameterTypes(sqlParameterTypes);
         ((SQLCall)sqlCall).setParameters(sqlParameters);
    //end code
    I hope this helps. The APIe changed from 9.0.4.5 to 10.1.3 so this code is for 10.1.3. Post if you have any more questions.
    Zev.

  • SQL*Plus Help

    Hi! Does anyone know where i can download SQL*Plus Help? I need to get info on select syntax, sql built-in functions, etc..
    Thanks!

    hi
    you can proceed like this :
    go to the OTN
    the click on products.
    null

  • How to install SQL*Plus help facilities and demos.

    Hi, everyone
    It appears error message say "failure to login" during SQL*Plus
    part of the Oracle8 full installation. I knew that system want
    to install SQL*Plus help and demos through logining one of
    dba account(maybe system user account). However, due to
    password's reason, can not log in SQL*Plus, so installer can't
    execute named pupbld.sql script, result in SQL*Plus help and
    demos can not be installed.
    Now, I am intend to install these stuff lonely.
    Could anyone help me? thank a lot.
    William
    null

    Hi,
    The pupbld.sql isn't the correct script to create the help
    facility, it just creates product and user profile tables.
    The help script is at $ORACLE_HOME/sqlplus/admin/help (run as
    system)
    cd $ORACLE_HOME/sqlplus/admin/help
    sqlplus system/<password> @helptbl
    sqlldr system/<password> control=plushelp.ctl
    sqlldr system/<password> control=plshelp.ctl
    sqlldr system/<password> control=sqlhelp.ctl
    sqlplus system/<password> @helpindx
    I think it is necessary to run the pupbld.sql script, without
    this script everyone who logins in oracle with sqlplus will see
    an error message, but... Run the script again:
    $ORACLE_HOME/sqlplus/admin/pupbld.sql
    Best regards,
    Ari
    William (guest) wrote:
    : Hi, everyone
    : It appears error message say "failure to login" during SQL*Plus
    : part of the Oracle8 full installation. I knew that system want
    : to install SQL*Plus help and demos through logining one of
    : dba account(maybe system user account). However, due to
    : password's reason, can not log in SQL*Plus, so installer can't
    : execute named pupbld.sql script, result in SQL*Plus help and
    : demos can not be installed.
    : Now, I am intend to install these stuff lonely.
    : Could anyone help me? thank a lot.
    : William
    null

  • Will Oracle pl/sql certification help me get  IT job

    Hello guys,
    I have completed my B.tech in Computer Science, I am confused a bit , Can i get a job after getting certified in Oracle Associate Pl/sql developer

    1005323 wrote:
    Hello guys,
    I have completed my B.tech in Computer Science, I am confused a bit , Can i get a job after getting certified in Oracle Associate Pl/sql developerYou may get a job after achieving Pl/sql developer OCA
    You may get a job after without achieving Pl/sql developer OCA
    You may fail to get a job after achieving Pl/sql developer OCA
    You may fail to get a job after without achieving Pl/sql developer OCA
    There are several factors involved in getting a job. And there are several ways a job may be obtained. But usually there are there stages:
    - Stage Zero: A company but has a job to offer.
    - And you need to be aware of it. - A friend may tell you, or an agency may tell you. And it must suit you for location and remuneration etc.
    - Stage one: An interview is obtained with the company.
    - Stage two: The job is offered to you rather than anyone else and you find it acceptable.
    So ... to your question:
    "Can i get a job after getting certified in Oracle Associate Pl/sql developer?"
    Well .... there is only three possible answers ... yes, no, and maybe; and maybe is probably the only correct answer, and most people will have worked this out, which means the question may have not been the best question to have asked.
    (( That said I now read the title of the thread and it says: Re: Will Oracle pl/sql certification help me get IT job)
    I have been known on occasion to have been given a question by a boss.
    And I have answered him:
    "You have given me the wrong question
    The question you should have answer me is this.
    And the answer I will give you is this."
    And the boss goes away happy
    So you you a better question would have been:
    How much will an OCA PL/SQL certification increase my chances of getting a job?
    Mind you even that question won't help you get a much better answer.
    For a proportion of jobs where PL/SQL is relevant that will help (for those where it is not it might be occasionally be a problem), for people with identical CV's it sometimes might help get to interview stage. But there are other factors as well. For instance if I was thinking of giving you a job on the basis of your post I might for example:
    - Not be impressed with an "Hello Guys" greeting ( though this is a forum so that isn't relevant here).
    - Not be impressed with you being confused.
    - etc.
    You probably need to get a good appreciation of the job market in your locality; and the numbers of applicants for each job. Which jobs you can apply for, what is your skillset and knowing youself as well.
    Sometimes an ITIL certification may be a better differentiator for some positions in business. But it will depend on the job you can think you can get.

  • (SQL*PLUS HELP) RUNNING PUPBLD OR HELPINS ASKS FOR SYSTEM_PASS

    제품 : ORACLE SERVER
    작성날짜 : 2002-04-22
    (SQL*PLUS HELP) RUNNING PUPBLD OR HELPINS ASKS FOR SYSTEM_PASS
    ==============================================================
    PURPOSE
    이 내용은 SQL*Plus 상에서 SQL*Plus command의 help를 보기 위한 방법이다.
    Problem Description
    SQL*Plus command의 help를 보기 위해서 helpins를 수행하면
    SYSTEM_PASS is not set이라는 에러 메시지가 발생하는 경우가 있다.
    이 자료는 pupbld 또는 helpins를 수행하기 전에 SYSTEM_PASS 환경변수를
    셋팅하는 방법에 대한 자료이다.
    아래와 같은 에러가 발생하는 경우 조치 방법에 대해 알아본다.
    SYSTEM_PASS not set.
    Set and export SYSTEM_PASS, then restart help (for helpins or
    profile for pupbld) installation.
    Workaround
    none
    Solution Description
    이 스크립트는 system user로 database에 connect되어 수행되어야 한다.
    helpins를 수행하기 위해서는 SYSTEM_PASS 환경변수가 셋팅되어 있어야 한다.
    NOTE
    For security reasons, do not set this variable in your shell
    startup scripts. (i.e. .login or .profile.).
    Set this environment variable at the prompt.
    1. Prompt에서 환경변수를 셋팅하기
    For C shell:
    % setenv SYSTEM_PASS system/<password>
    For Korn or Bourne shells:
    $ SYSTEM_PASS=system/<password> ;export SYSTEM_PASS
    2. Now run "$ORACLE_HOME/bin/pupbld" or "$ORACLE_HOME/bin/helpins".
    % cd $ORACLE_HOME/bin
    % pupbld
    or
    % helpins
    주의사항
    $ORACLE_HOME/bin/pupbld 스크립트와 $ORACLE_HOME/bin/helpins 스크
    립트를 수행하기 위해서는 반드시 SYSTEM_PASS 환경변수를 필요로 한다.
    Reference Document
    <Note:1037075.6>

    check it please whether it is a database version or just you are installing a client. Install Enterprize database on 2k system. I you are running a client software then you are to deinstall it.

  • Download Oracle SQL*Plus help related like word help

    Hello all
    I just wanna ask if where i can download Oracle SQL*Plus help related like word help.?
    ty

    <p>You can access SQL*Plus help from the command line in a SQL*Plus session by typing 'help index'. If you want more information than that, take a look at the SQL*Plus Quick Reference located <b>here</b> or the SQL*Plus User's Guide and Reference located <b>here</b>. These docs are all for Oracle 10g. Other version documentation can be found <b>here</b>.</p>
    Tom

  • SQL Server2008 help needed

    Having trouble with SQLServer 2008 (not MySQL) and my database connection in Dreamweaver CS6.  My document type is set as .asp using VBScript.  I can list the table information  but cannot use the insert wizard to add new records.  I don't get any errors after creating the insert form, but no records get inserted.  I'm not a VBScript expert, but do I have to manually write some code to insert records?  How do I attach it to a button?

    Thanks for the quick reply.  I won't be back in the office for a few days, but I'll try to post it when I get back in.  It's pretty much the code generated from the Dreamweaver Insert Record wizard.  I see where the submit button is created and the value is set but the action on the form is set to MM_insert, so I don't see where the submit code is actually called.
    Date: Wed, 3 Oct 2012 12:06:14 -0600
    From: [email protected]
    To: [email protected]
    Subject: SQL Server2008 help needed
        Re: SQL Server2008 help needed
        created by bregent in Dreamweaver General - View the full discussion
    This post should be moved to the app dev forum.  Please post the code from your form and the insert script pages.
         Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/4746757#4746757
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4746757#4746757
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4746757#4746757. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Dreamweaver General by email or at Adobe Community
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • Need help in SQL - subquery

    I have 2 tables.
    Tbl1 (col1, col2)
    Tbl2 (col1, col2)
    all columns are varchar
    I am writing a sub query like:
    select * from tbl1 where col1 in (select col1 from tbl2) this works perfectly
    1) Now I am writing a function which returns a single value
    create function f2 return varchar
    as
    v2 varchar2(100);
    v2:='8117';
    return v2;
    end;
    select * from tbl1 where col1 in (f2) -- this works perfectly...
    2) Now I am writing a function like:
    create function f2 return varchar
    as
    v2 varchar2(100);
    v2:='select col1 from tbl2';
    return v2;
    end;
    select * from tbl1 where col1 in (f2) -- this is not working... the function f2 is returning a single value
    any suggestions?
    Thanks,
    Ash

    Hi ashishprem,
    My suggestion is that you use INSTR... something like this
    SQL> Select * from emp where instr(',' || '7369' || ',' , ',' || EMPNO || ',') > 0;
    EMPNO ENAME      JOB         MGR HIREDATE          SAL      COMM DEPTNO
    7369 SMITH      CLERK      7902 17/12/1980     800,00               20or
    SQL> Select * from emp where instr(',' || 'SMITH,JONES,MARTIN' || ',' , ',' || ENAME || ',') > 0;
    EMPNO ENAME      JOB         MGR HIREDATE          SAL      COMM DEPTNO
    7369 SMITH      CLERK      7902 17/12/1980     800,00               20
    7566 JONES      MANAGER    7839 2/4/1981      2975,00               20
    7654 MARTIN     SALESMAN   7698 28/9/1981     1250,00   1400,00     30or
    SQL> Select * from emp where instr(ename,(select ename from emp where ename = 'ALLEN')) > 0;
    EMPNO ENAME      JOB         MGR HIREDATE          SAL      COMM DEPTNO
    7499 ALLEN      SALESMAN   7698 20/2/1981     1600,00    300,00     30Hope this helps,
    Christian Balz

  • Help with sql subquery/grouping

    Hi... having trouble getting this query to work. Here's the table and data:
    create table mytable (
    rec_num number,
    status_num number,
    status_date date
    insert into mytable values (1,1,'01-AUG-2006');
    insert into mytable values (1,2,'14-AUG-2006');
    insert into mytable values (1,8,'01-SEP-2006');
    insert into mytable values (1,3,'15-SEP-2006');
    insert into mytable values (1,2,'03-SEP-2006');
    insert into mytable values (2,2,'17-AUG-2006');
    insert into mytable values (3,2,'02-SEP-2006');
    insert into mytable values (3,4,'07-SEP-2006');
    insert into mytable values (4,1,'18-SEP-2006');
    insert into mytable values (4,4,'27-SEP-2006');
    insert into mytable values (4,2,'18-SEP-2006');
    insert into mytable values (5,1,'01-OCT-2006');
    insert into mytable values (5,2,'03-OCT-2006');
    insert into mytable values (5,3,'05-OCT-2006');
    insert into mytable values (6,1,'01-OCT-2006');
    insert into mytable values (7,2,'14-OCT-2006');
    insert into mytable values (7,8,'15-OCT-2006');
    I'm trying to select the rec_num, status_num, and status_date for the max date for each individual rec_num... it basically tells me the current status of each individual record by getting the status for the most recent date... like the following:
    rec_num, status_num, date
    1, 3, 15-SEP-2006
    2, 2, 17-AUG-2006
    3, 4, 07-SEP-2006
    etc
    This query works... it gets me the max date for each record... but it doesn't give me the status_num:
    select rec_num, max(status_date)
    from mytable
    group by rec_num
    Adding status_num messes it up... I know I need some kindof sub-query, but haven't been able to get one to work.
    I'd also like a query to get a count on how many records currently exist in each status.
    Can someone help me out? Oracle 8i. Thanks!

    SQL> select * from my_table;
       REC_NUM STATUS_NUM STATUS_DA
             1          1 01-AUG-06
             1          2 14-AUG-06
             1          8 01-SEP-06
             1          3 15-SEP-06
             1          2 03-SEP-06
             2          2 17-AUG-06
             3          2 02-SEP-06
             3          4 07-SEP-06
             4          1 18-SEP-06
             4          4 27-SEP-06
             4          2 18-SEP-06
             5          1 01-OCT-06
             5          2 03-OCT-06
             5          3 05-OCT-06
             6          1 01-OCT-06
             7          2 14-OCT-06
             7          8 15-OCT-06
    SQL> select mt.rec_num,
      2         mt.status_num,
      3         mt.status_date
      4    from (select row_number() over (partition by rec_num order by status_date desc) rn,
      5                 rec_num,
      6                 status_num,
      7                 status_date
      8            from my_table) mt
      9   where mt.rn = 1;
       REC_NUM STATUS_NUM STATUS_DA
             1          3 15-SEP-06
             2          2 17-AUG-06
             3          4 07-SEP-06
             4          4 27-SEP-06
             5          3 05-OCT-06
             6          1 01-OCT-06
             7          8 15-OCT-06
    7 rows selected.
    SQL>

  • Help Required With SQL Subquery Across DB Link - Takes Long Time

    Hi,
    Apologies if this is not the correct forum but I am implementing this through HTMLDB.
    I am trying to run a SQL query over a DB link with a sub query on tables in my HTMLDB workspace.
    The SQL query over the database link takes 1.23 seconds to run on it's own:
    SELECT D.EMAIL_ADDRESS,
    D.COL2,
    D.COL3,
    D.COL4,
    D.COL5,
    D.COL6,
    T.COL1
    FROM SCHEMA.TABLE1@DATABASELINK D,
    SCHEMA.TABLE2@DATABASELINK T
    WHERE D.TABLE_JOIN = T.TABLE_JOIN
    AND T.COL1 = '1111111'
    AND UPPER(D.COL2) IN ('XXXXXX','YYYYYY')
    The SQL query based on HTMLDB workspace tables takes 0.01 seconds to run on it's own:
    SELECT UPPER(A.EMAIL_ADDRESS)
    FROM HTMLDBTABLE1 M, HTMLDBTABLE2 A
    WHERE M.TABLE_JOIN = A.TABLE_JOIN
    AND M.ID = 222
    However when I try and run these together the results take 280 seconds to complete:
    SELECT D.EMAIL_ADDRESS,
    D.COL2,
    D.COL3,
    D.COL4,
    D.COL5,
    D.COL6,
    T.COL1
    FROM SCHEMA.TABLE1@DATABASELINK D,
    SCHEMA.TABLE2@DATABASELINK T
    WHERE D.TABLE_JOIN = T.TABLE_JOIN
    AND T.COL1 = '1111111'
    AND UPPER(D.COL2) IN ('XXXXXX','YYYYYY')
    AND NOT EXISTS
    (SELECT UPPER(A.EMAIL_ADDRESS)
    FROM HTMLDBTABLE1 M, HTMLDBTABLE2 A
    WHERE M.TABLE_JOIN = A.TABLE_JOIN
    AND UPPER(A.EMAIL_ADDRESS) = UPPER(D.EMAIL_ADDRESS)
    AND M.ID = 222)
    Does anyone have any idea why this query is taking so long?
    Please let me know if you require additional information.
    Many thanks,
    Richard.

    I've updated my profile to show my email address, so go ahead and email me the strace output (compressed please). Maximum attachment size for emails to Oracle is 10MB (encoded), so split the strace output in 5MB chunks if necessary.
    poll() is not normally used by the Oracle network layer for client-server connections. So this may be related to an OS network service, such as DNS or NIS. The strace should make this clear (to me anyway).
    Edited by: herb on Aug 14, 2009 10:25 AM

  • Sql rewrite help

    I have a select statemnet like below.. it currently returns 3 rows. I want the the last value from this query below. so i want only "4" returned from this query. How to achieve it ? Thanks for the help.
    SQL
    SELECT  col6
    FROM  TableA
    WHERE  col1=12
    AND    col2='B'
    AND    col3='001'
    AND    col4='455'
    AND    col5='666'
    ORDER BY col1, col2, col3,col5, col4 desc
    curent output
    1
    5
    4
    expected output
    4

    Etbin wrote:
    Maybe NOT TESTED!
    select col6
      from (select col6,rownum rn
              from (SELECT col6
                      FROM TableA
                     WHERE col1 = 12
                       AND col2 = 'B'
                       AND col3 = '001'
                       AND col4 = '455'
                       AND col5 = '666'
                     ORDER BY col1,col2,col3,col5,col4 desc
             order by rn desc
    where rownum = 1
    Regards
    Etbin
    Hi,
    Please correct me if I'm wrong, (I didn't test your solution ), but I think there could be a problem in your query which has the following form:
    SELECT col6       -
    FROM
         SELECT col6, rownum rn     -- 1st subquery
         FROM
               SELECT col6          -- 2nd subquery
               FROM     . . .
               ORDER BY . . .
         ORDER BY rn DESC
    WHERE rownum = 1
    The global query is a top-n-reporting so the order defined in "1st subquery" is conserved within the global query thanks to WHERE rownum = 1, however the order defined by the ORDER BY clause of the "2nd subquery" is not necessarily relevant inside "1st subquery" as there is no top-n structure at this level (inside 1st subquery). In otherwords rownum will not enumerate rows based on the order in the 2nd subquery that the OP defined, that is ORDER BY col1,col2,col3,col5,col4 desc,
    Regards,
    Dariyoosh

  • Correlatd Subquery help needed for 8i

    Hi Everyone,
    I am struggling with a correlated subquery, the individual parts of which work fine, but not together! I am guessing that this is something to do with the SQL implementation in Oracle 8i and the way that it handles table references, but I am not sure how to approach this for a workable solution. Any help would be greatly appreciated.
    Here is my SQL:
    select
    TA.JAHR as yr,
    TB.WOCHE as week,
    (select count(*) from (
    SELECT T2.JAHR
    , T2.KUNDEN_ID
    , CDW.PRODUKTE.EAN_VBE
    , T3.WOCHE
    , Sum(T2.ANZ_VSE)
    FROM CDW.RECHNUNGSPOSITIONEN T2
    JOIN CDW.PRODUKTE ON CDW.PRODUKTE.ID = T2.PRODUKT_ID
    JOIN CDW.KALENDER T3 ON T3.DATUM = T2.RECHNUNG_DATUM
    WHERE T2.JAHR = TA.JAHR
    AND CDW.PRODUKTE.SEGMENT Like 'PET%'
    AND T3.WOCHE = TB.WOCHE
    AND T2.AUFTRAGS_ART_ID NOT IN (39,48)
    AND CDW.PRODUKTE.EAN_VBE <> 0
    GROUP BY T2.JAHR
    , T2.KUNDEN_ID
    , T3.WOCHE
    , CDW.PRODUKTE.EAN_VBE
    )) as qty
    FROM
    CDW.RECHNUNGSPOSITIONEN TA
    JOIN
    CDW.KALENDER TB ON TB.DATUM = TA.RECHNUNG_DATUM
    WHERE
    TA.JAHR >= 2005
    GROUP BY
    TA.JAHR,
    TB.WOCHE
    It looks as though the inner query cannot use the table references in the outer query. Am I missing something?
    Cheers and thanks in advance
    The Frog

    The SQL Standard defines correlation variables at only one level deep. In your case you were trying to reference a table (TA and TB) at the 2nd level. In this case it may be easier to remove this inline subquery altogether. I tried to simplify your query. This is just a guess and it's not tested:
    SELECT  TA.JAHR as yr
    ,       TB.WOCHE as week
    ,       COUNT(*) as qty
    FROM    CDW.RECHNUNGSPOSITIONEN TA
    JOIN    CDW.KALENDER            TB      ON TB.DATUM             = TA.RECHNUNG_DATUM
    JOIN    CDW.RECHNUNGSPOSITIONEN T2      ON TA.JAHR              = T2.JAHR
    JOIN    CDW.PRODUKTE                    ON CDW.PRODUKTE.ID      = T2.PRODUKT_ID
    JOIN    CDW.KALENDER            T3      ON T3.DATUM             = T2.RECHNUNG_DATUM
                                           AND T3.WOCHE             = TB.WOCHE
    WHERE   CDW.PRODUKTE.SEGMENT Like 'PET%'
    AND     T2.AUFTRAGS_ART_ID NOT IN (39,48)
    AND     CDW.PRODUKTE.EAN_VBE != 0
    AND     TA.JAHR >= 2005
    GROUP BY        TA.JAHR
    ,               TB.WOCHEIt's always helpful to post the following:
    1. FULL Oracle version (SELECT * FROM V$VERSION)
    2. Sample data in the form of CREATE / INSERT scripts.
    3. Expected output.
    4. Explanation on how to achieve expected output.
    5. Please use \ tags to surround anything that requires fixed-width spacing like SQL statements.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Sql query help

    hi guys
    i have sample data as mentioned below... need to find the duplicate rows where cd=cd and dt1=dt1 and tm1 difference should be less than or equal to 4 hrs..
    i can get the data with the query written below but my problem is that i am not allowed to use in-built sql server function... can you help me in writing the same without using in-built function...
    CREATE TABLE #t (id INT,dt1 datetime, tm1 datetime,cd varchar(10))
    INSERT INTO #t VALUES (101,'2013-04-24','1900-01-01 12:20:00.000','TC')
    INSERT INTO #t VALUES (101,'2013-04-24','1900-01-01 12:30:00.000','TC')
    INSERT INTO #t VALUES (101,'2013-08-02','1900-01-01 14:30:00.000','MN')
    INSERT INTO #t VALUES (101,'2013-08-02','1900-01-01 15:07:00.000','MN')
    INSERT INTO #t VALUES (101,'2013-07-06','1900-01-01 09:07:00.000','XY')
    INSERT INTO #t VALUES (101,'2013-11-27','1900-01-01 09:50:00.000','LM')
    INSERT INTO #t VALUES (101,'2013-07-06','1900-01-01 15:07:00.000','XY')
    select * From #t
    WITH MyCTE (rn,id, dt1, tm1, cd)
    AS(
    select row_number() over (partition by id ORDER BY dt1, tm1) rn,* from #t
    select case when ((dt1 = lead_start_Date) and (ct <='4.0') and (base_cd = lead_cd)) then 'Duplicate_Req' else '' end dt123,* from
    select abs(convert(decimal(5,1),datediff(MI,lead_Start_time,tm1)/60.00)) ct, * from
    SELECT base.rn b_rn,LEAd.rn l_rn,BASE.id
    ,BASE.dt1
    ,BASE.tm1
    ,base.cd base_cd
    ,LEAD.dt1 LEAD_START_DATE
    ,LEAD.tm1 LEAD_START_TIME
    ,lead.cd lead_cd
    --,DATEADD(dd,-1,LEAD.dt1) EXPECTED_END_DATE
    FROM MyCTE BASE
    LEFT JOIN MyCTE LEAD ON BASE.id = LEAD.id
    AND BASE.rn = LEAD.rn+1
    ) b
    )c

    if this code will not work for you then not sure if there are any other options
    Converted the CTE into an actual temp table.
    CTE and barebones T-SQL code are included in the script below.
    CREATE TABLE #t (id INT,dt1 datetime, tm1 datetime,cd varchar(10))
    INSERT INTO #t VALUES (101,'2013-04-24','1900-01-01 12:20:00.000','TC')
    INSERT INTO #t VALUES (101,'2013-04-24','1900-01-01 12:30:00.000','TC')
    INSERT INTO #t VALUES (101,'2013-08-02','1900-01-01 14:30:00.000','MN')
    INSERT INTO #t VALUES (101,'2013-08-02','1900-01-01 15:07:00.000','MN')
    INSERT INTO #t VALUES (101,'2013-07-06','1900-01-01 09:07:00.000','XY')
    INSERT INTO #t VALUES (101,'2013-11-27','1900-01-01 09:50:00.000','LM')
    INSERT INTO #t VALUES (101,'2013-07-06','1900-01-01 15:07:00.000','XY')
    INSERT INTO #t VALUES (101,'2013-08-02','1900-01-01 15:07:00.000','MN')
    select * From #t
    ;WITH MyCTE (rn,id, dt1, tm1, cd)
    AS(
    select row_number() over (partition by id ORDER BY dt1, tm1) rn,* from #t
    select case when ((dt1 = lead_start_Date) and (ct <='4.0') and (base_cd = lead_cd)) then 'Duplicate_Req' else '' end dt123,* from
    select abs(convert(decimal(5,1),datediff(MI,lead_Start_time,tm1)/60.00)) ct, * from
    SELECT base.rn b_rn,LEAd.rn l_rn,BASE.id
    ,BASE.dt1
    ,BASE.tm1
    ,base.cd base_cd
    ,LEAD.dt1 LEAD_START_DATE
    ,LEAD.tm1 LEAD_START_TIME
    ,lead.cd lead_cd
    --,DATEADD(dd,-1,LEAD.dt1) EXPECTED_END_DATE
    FROM MyCTE BASE
    LEFT JOIN MyCTE LEAD ON BASE.id = LEAD.id
    AND BASE.rn = LEAD.rn+1
    ) b
    )c
    select * into #copy From #t order by id, cd, dt1, tm1
    alter table #copy add seqno int identity(1,1)
    select distinct y.id,y.cd,y.dt1,y.tm1,y.seqno,case when z.cd is not null then 'Duplicate_Req' else '' end dt123
    from #copy y
    left outer join
    (select a.id,a.cd,a.dt1,a.tm1
    From #copy a
    left outer join #copy b
    on a.id = b.id
    and a.cd = b.cd
    and a.dt1 = b.dt1
    where a.seqno > b.seqno
    and abs(datediff(MINUTE,b.tm1,a.tm1)) <= 240) z
    on y.id = z.id
    and y.cd = z.cd
    and y.dt1 = z.dt1
    and y.tm1 = z.tm1
    order by y.dt1,y.tm1
    drop table #copy
    drop table #t

  • SQL Query Help Needed

    I'm having trouble with an SQL query. I've created a simple logon page wherein a user will enter their user name and password. The program will look in an Access database for the user name, sort it by Date/Time modified, and check to see if their password matches the most recent password. Unfortunately, the query returns no results. I'm absolutely certain that I'm doing the query correctly (I've imported it directly from my old VB6 code). Something simple is eluding me. Any help would be appreciated.
    private void LogOn() {
    //make sure that the user name/password is valid, then load the main menu
    try {
    //open the database connection
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:LawOffice2000", "", "");
    Statement select = con.createStatement();
    String strTemp = "Select * From EMPLOYEES Where INITIALS = '" + txtUserName.getText() + "' Order By DATE Desc, TIME Desc";
    ResultSet result = select.executeQuery(strTemp);
    while(result.next()) {
    if (txtPassword.getPassword().toString() == result.getString("Password")) {
    MenuMain.main();
    else {
    System.out.println("Password Bad");
    System.out.println(txtUserName.getText());
    System.out.println(result.getString("Password"));
    break; //exit loop
    //close the connection
    con.close(); }
    catch (Exception e) {
    System.out.println("LawOfficeSuite_LogOn: " + e);
    return; }
    }

    The problem is here: "txtPassword.getPassword().toString() == result.getString("Password"))"
    Don't confuse String's equals() method with the equality operator '=='. The == operator checks that two references refer to the same object. If you want to compare the contents of Strings (whether two strings contain the same characters), use equals(), e.g. if (str1.equals(str2))...
    Example:String s1 = "foo";
    String s2 = new String("foo");
    System.out.println("s1 == s2: " + (s1 == s2)); // false
    System.out.println("s1.equals(s2): " + (s1.equals(s2))); // trueFor more information, check out Comparison operators: equals() versus ==

Maybe you are looking for

  • Question about moving all iTunes data from one computer to another.

    I have a Windows XP. Now I have a windows 7. All of the songs from the XP are available on the new computer via a Z drive. But when I plug my iPod into the new computer it says that it is registered with a different library and asks me if I want to d

  • Problems with uploading photos to Facebook - Photoshop elements 9

    Yesterday I was able to upload photos to Facebook with no problems, but today I just keep getting a message to say I can't upload.  I get a message saying "there is a problem with your internet connection.  Please check that the firewall is not block

  • Where is the serialnumber for instaling photoshop 12

    Have bought photshop premiere elements 12, but where can i find the serialnumber to install the CD.

  • Spinning beach ball at login after 10.5.6 update

    Since I upgraded to 10.5.6, the spinning beach ball would appear every time at startup. At the same time, Finder (and/or the menu bar) is frozen and the Dock doesn't show up. Here are the suspicious error messages in Console: 2008/12/19 上午 1:44:31 Fi

  • Create Local Variable in Custom.pll

    Hi, I want to create and calling local variable in custom.pll. As i know, we can create local variable with personalization form. but i didn't find the way to create local variable in custom.pll. Is there any way to create local variable in custom.pl