Using varchar record in SELECT query

Hi, from a VARCHAR field I get the string ",1,2,3,4,5,6,".
I wish to use it in a SELECT query like:
SELECT * FROM TABLE WHERE ID IN (1,2,3,4,5,6)
Is there a way to obtain this in a tsql query ?
Thank you
Stefano

CREATE TABLE t1
 col1 INT NOT NULL PRIMARY KEY,
 col2 VARCHAR(50) NOT NULL
INSERT INTO t1 VALUES (1,'10,11,12')
INSERT INTO t1 VALUES (2,'13')
INSERT INTO t1 VALUES (3,'14,15')
CREATE TABLE t2
 col1 INT NOT NULL PRIMARY KEY,
 col2 VARCHAR(50) NOT NULL
INSERT INTO t2 VALUES (10,'A')
INSERT INTO t2 VALUES (11,'B')
INSERT INTO t2 VALUES (12,'C')
INSERT INTO t2 VALUES (13,'D')
INSERT INTO t2 VALUES (14,'E')
INSERT INTO t2 VALUES (15,'F')
SELECT DISTINCT O.col1, O.col2
FROM t1 T
   INNER JOIN t2 O
      ON (PATINDEX('%,' + CAST(O.col1 AS varchar(10)) + ',%',
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

  • Check Index used in an oracle select query

    Hi Friends,
    I have partitioned an oracle table and created Local Index for the Partitioned table .
    Now i want to make sure that the Local index is being used when i perform select query on the Table partition.
    How do i confirm that ?
    can i check the explain plan generted for the select query to confirm local index is being used ?
    Please let me know.
    Regards,
    DB

    Now i want to make sure that the Local index is being used when i perform select query on the Table partition.Why? Have you proven that using this local index is the "best" plan?
    How do i confirm that ?
    can i check the explain plan generted for the select query to confirm local index is being used ?When I asked Google "how to read an oracle explain plan," I found lots of information - what did you find?

  • How can i use SUM aggregate in select query?

    HI,
    GURUS,
    How can i use SUM function in Select Query and i want to store that value into itab.
    for ex:
    TABLES: vbap.
    types: begin of ty_vbap,
           incluse type vbap,
           sum type string,
          end of ty_vbap.
    data: i_vbap type TABLE OF ty_vbap,
          w_vbap type ty_vbap.
    SELECT sum(posnr) FROM vbap into table i_vbap up to 5 rows.
                            (or)
    SELECT sum(posnr) FROM vbap into table i_vbap group by vbeln.
      loop at i_vbap into w_vbap
    " which variable have to use to display summed value.
      endloop.
    if above code is not understandable pleas give ome sample code on  above query.
    Thank u,
    shabeer ahmed.

    Hi,
    Check this sample code.
    TABLES SBOOK.
    DATA:  COUNT TYPE I, SUM TYPE P DECIMALS 2, AVG TYPE F.
    DATA:  CONNID LIKE SBOOK-CONNID.
    SELECT CONNID COUNT( * ) SUM( LUGGWEIGHT ) AVG( LUGGWEIGHT )
           INTO (CONNID, COUNT, SUM, AVG)
           FROM SBOOK
           WHERE
             CARRID   = 'LH '      AND
             FLDATE   = '19950228'
           GROUP BY CONNID.
      WRITE: / CONNID, COUNT, SUM, AVG.
    ENDSELECT.
    Regards,
    Sravanthi

  • Is there a way to use owa_opt_lock.checksum in Select query that returns multiple records?

    Trying to do something as data would be uploaded and edited in grid. At present I am using Ora_Hash.
    SELECT
            e.ROWID, e.Employee_Id,e.First_Name,e.Last_Name,e.Email,e.Phone_Number,e.Hire_Date,
            e.Job_Id,e.Salary,e.Manager_Id,e.Department_Id,
            owa_opt_lock.checksum('HR','EMPLOYEES', e.rowid) As HashForThisRow
    FROM EMPLOYEES e;
    Thx

    No you can't.
    owa_opt_lock.checksum is a function which is used for optimist locking. It locks the row(probably by using Select FOR Update mechanism) which you select and which you are trying to update. As a result, what you are eventually trying to do is that inside a Select query you are using a function that is locking the rows, which is not allowed. And thus your query will fail with the below mentioned error.
    ORA-14551: cannot perform a DML operation inside a query
    ORA-06512: at "SYS.DBMS_SQL", line 1575
    ORA-06512: at "SYS.OWA_OPT_LOCK", line 172
    14551. 00000 -  "cannot perform a DML operation inside a query "
    *Cause:    DML operation like insert, update, delete or select-for-update
               cannot be performed inside a query or under a PDML slave.
    *Action:   Ensure that the offending DML operation is not performed or
               use an autonomous transaction to perform the DML operation within
               the query or PDML slave.
    Thanks,
    Ishan

  • Sample XML format that can be used to write a SELECT query

    Hello,
    I want to use and XML file in the scenario FILE to JDBC where i use the operation as SELECT in which i want to embbed an sql statemnet which is equivalent to
    SELECT EMPNO, NAME FROM EMPLOYEE WHERE EMPNO>1
    as in the form of XML format like,
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:MT_JDBC_SELECT_JDBC_REQ xmlns:ns0="http://JDBC_SELECT">
    <STATEMENT>
    <TABLENAME ACTION="SELECT">
    <TABLE>EMPTEST</TABLE>
    <ACCESS>
    <EMPNO></EMPNO>
    <NAME></NAME>
    </ACCESS>
    <KEY>
    <EMPNO compareOperation="GT">1</EMPNO>
    </KEY>
    </TABLENAME>
    </STATEMENT>
    </ns0:MT_JDBC_SELECT_JDBC_REQ>
    Can i do like this?
    PLease help me out in using various conditions in the XML file formats like the above.
    Thanks,
    Soorya.

    Hello raj,
    I would like to write the query in that format where i mentioned as,
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:MT_JDBC_SELECT_JDBC_REQ xmlns:ns0="http://JDBC_SELECT">
    <STATEMENT>
    <TABLENAME ACTION="SELECT">
    <TABLE>EMPTEST</TABLE>
    <ACCESS>
    <EMPNO></EMPNO>
    <NAME></NAME>
    </ACCESS>
    <KEY>
    <EMPNO compareOperation="GT">1</EMPNO>
    </KEY>
    </TABLENAME>
    </STATEMENT>
    </ns0:MT_JDBC_SELECT_JDBC_REQ>
    without giving clear SQL statement as you mentioned here like,
    <ns0:MT_JDBC_SELECT_JDBC_REQ xmlns:ns0="http://JDBC_SELECT">
    <STATEMENT>
    <TABLENAME ACTION="SQL_QUERY">
    <ACCESS>SELECT EMPNO, NAME FROM EMPLOYEE WHERE EMPNO > '$EMPNO$’</ACCESS>
    <KEY>
    <EMPNO>1</EMPNO>
    </KEY>
    </TABLENAME>
    </STATEMENT>
    </ns0:MT_JDBC_SELECT_JDBC_REQ>
    Thanks,
    Soorya

  • Using buffering option in select query

    Hi All,
           Can anybody give me a brief idea on , where we will use the buffering and how we will write it in coding part.Similarly please tell me what will happen if we use  by passing buffering  addition in select query. Please explain  it with steps of sample code if possible.
    Thanks in advance.
    Regards,
    Rakesh.

    Hi Sharma,
    Buffer is used to hold large amount of data.
    if internla table is unable to hold data.. Buffer is used..this is mainly used in copy data from PRD to Quality as a part testung.
    see the sample code how the buffer is used..
    FUNCTION zzrfc_get_zcpeg_fg_related.
    *"*"Local Interface:
    *"  IMPORTING
    *"     VALUE(PL_VERSION) LIKE  ZCPEG_FG_RELATED-PL_VERSION OPTIONAL
    *"     VALUE(BYPASS_BUFFER) LIKE  SY-FTYPE DEFAULT SPACE
    *"     VALUE(FROM_KEY) LIKE  SY-ENTRY DEFAULT SPACE
    *"     VALUE(GEN_KEY) LIKE  SY-ENTRY DEFAULT SPACE
    *"     VALUE(MAX_ENTRIES) LIKE  SY-TABIX DEFAULT 0
    *"     VALUE(TABLE_NAME) LIKE  X030L-TABNAME
    *"     VALUE(TO_KEY) LIKE  SY-ENTRY DEFAULT SPACE
    *"  EXPORTING
    *"     VALUE(NUMBER_OF_ENTRIES) LIKE  SY-INDEX
    *"  TABLES
    *"      ENTRIES STRUCTURE  ZCPEG_FG_RELATED
    *"  EXCEPTIONS
    *"      INTERNAL_ERROR
    *"      TABLE_EMPTY
    *"      TABLE_NOT_FOUND
      TABLES dd02l.
      DATA: BEGIN OF buf OCCURS 100,
                line(4100),
            END OF buf.
      DATA keyln TYPE i.
      DATA: l_tabname LIKE dd25v-viewname.
      DATA: l_len     TYPE i.
      DATA : w_plversion TYPE /sapapo/vrsioex.   "PJONNALA
      w_plversion =  pl_version.                 "PJONNALA
      l_tabname = table_name.
      CALL FUNCTION 'VIEW_AUTHORITY_CHECK'
        EXPORTING
          view_action                = 'S'
          view_name                  = l_tabname
          no_warning_for_clientindep = 'X'
        EXCEPTIONS
          OTHERS                     = 6.
      IF sy-subrc <> 0.
        RAISE internal_error.
      ENDIF.
      IF bypass_buffer NE ' ' AND bypass_buffer NE 'N'.
        bypass_buffer = 'Y'.
      ENDIF.
      IF gen_key CA ' '. ENDIF.
      keyln = sy-fdpos.
    * read client dependant tables always with client
      SELECT SINGLE * FROM dd02l WHERE tabname = table_name
                                  AND as4local =  'A'.
      IF dd02l-clidep = 'X'.
    *l_len = strlen( sy-mandt ) * cl_abap_char_utilities=>charsize.
    *  " ecwg. unicode
    *    move gen_key to gen_key+l_len.
    *    move sy-mandt to gen_key(l_len).
    *    add l_len to keyln.
        CONCATENATE sy-mandt gen_key INTO gen_key.
        keyln = STRLEN( gen_key ) * cl_abap_char_utilities=>charsize.
      ENDIF.
    *  endselect.
      IF keyln NE 0 OR from_key = space.
        CALL 'C_GET_TABLE' ID 'TABLNAME'  FIELD table_name
                           ID 'INTTAB'    FIELD buf-*sys*
                           ID 'GENKEY'    FIELD gen_key
                           ID 'GENKEY_LN' FIELD keyln
                           ID 'DBCNT'     FIELD number_of_entries
                           ID 'BYPASS'    FIELD bypass_buffer.
      ELSE.
        CALL 'C_GET_TABLE' ID 'TABLNAME'  FIELD table_name
                           ID 'INTTAB'    FIELD buf-*sys*
                           ID 'FROM_KEY'  FIELD from_key
                           ID 'TO_KEY'    FIELD to_key
                           ID 'DBCNT'     FIELD number_of_entries
                           ID 'BYPASS'    FIELD bypass_buffer.
      ENDIF.
      CASE sy-subrc.
        WHEN 4.  RAISE table_empty.
        WHEN 8.  RAISE table_not_found.
        WHEN 12. RAISE internal_error.
      ENDCASE.
      DESCRIBE TABLE buf LINES number_of_entries.
    ENDFUNCTION.
    Regards,
    Prabhudas

  • How can i use param in my select query ( see code)

    Hi ,
    I need to use the param instead of hardcoding the value in the select query , when i did that it is working .
    I think the limit of args is only till the end of main and my select query is in a method called Load() .
    How can i use the param in my select query .
    public static void main(String[] args){
    name = args[0];
    class= args[1];
    new Load();
    }//end of main
    public Load()
              try {
                   Class.forName(JDBC_DRIVER);
                   connection = DriverManager.getConnection(DATABASE_URL,"username","pw");
                   statement = connection.createStatement();
                   //First Query : pin and ticket number
                   ResultSet resultSet = statement.executeQuery("SELECT pin , ticketnumber from airport ,year where "+                                                                      "year.year_name= Here i need to use the param (instead of hardcoding) and year.class_year= Here too i need to use param");
    }// end of method Load()Edited by: 1sai on Sep 24, 2008 7:34 AM
    Edited by: 1sai on Sep 24, 2008 7:35 AM

    Might I suggest you change the structure of your program to the following:
    public class Load {
      private Connection conn;
      private PreparedStatement statement;
      public Load(String sql) {
        init(sql);
      protected void init(String sql) throws Exception {
        Class.forName(JDBC_DRIVER);
        conn = DriverManager.getConnection(DATABASE_URL, "username", "pw");
        statement = conn.prepareStatement(sql);
      public ResultSet execute(String p1, String p2) throws Exception {
        statement.setString(1, p1);
        statement.setString(2, p2);
        return statement.executeQuery();
      public void close() throws Exception {
        if (statement != null)
          statement.close();
        statement = null;
        if (conn != null)
          conn.close();
        conn = null;
      public static void main(String[] args) throws Exception {
        String sql = args[0];
        String param1 = args[1];
        String param2 = args[2];
        Load load = new Load(sql);
        ResultSet rs = load.execute(param1, param2);
        while (rs.next())
          System.out.println(rs.get(0));
        rs.close();
        load.close();
    }This allows you to use the same "Load" object for multiple queries with different parameters.
    I do not recommend you actually use the code above in any sort of production application. You should really take a look at Spring Framework along with an ORM tool like Hibernate or Ibatis to simplify your DAO layer.
    Hope this helps,
    David

  • Using DB Links - Improving SELECT query performance

    Hi there,
    I am using dblink in the following query:
    I would like to improve performance of the query by using hints as per described in the link: http://www.experts-exchange.com/Database/Oracle/9.x/Q_23640348.html. However, i am not sure how can i include this in my select query.
    Details are:
    Oracle - 9i Database Terminal Release .8
    DB Link: TCPROD
    Could someone please explain with an example how to use hints to get the query to select data on the remote database and then return the results to the target database?
    Many Thanks.
    SELECT ec.obid AS prObid,
                 ec.b2ProgramName AS program,
                 ec.projectName AS project,
                 ec.wbsID AS prNo,
                 ec.wbsName AS title,
                 ec.revision AS revision,
                 ec.superseded AS revisionSuperseded,
                 ec.lifeCycleState AS lifeCycleState,
                 ec.b2ChangeType AS type,
                 ec.b2Complexity AS subType,
                 ec.r1SsiCode AS ssi,
                 ec.b2disposition as disposition,
                 ec.wbsOriginator AS requestor,
                 ec.wbsAdministrator AS administrator,
                 ec.changepriority as priority,
                 ec.r1tsc as tsc,
                 ec.t1comments as tenixComments,
                 ec.b2securityclass as securityClassification,
                 ec.t1changesafety as safety,
                 ec.t1actionofficer as actionOfficer,
                 ec.t1changereason as changeReason,
                 ec.t1wbsextchangenumber as extChangeNo,
                 ec.creator as creator,
                 to_date(substr(ec.creationdate,
                                0,
                                instr(ec.creationdate, ':', 1, 3) - 1),
                         'YYYY/MM/DD-HH24:MI:SS') as creationdate,
                 to_date(ec.originatorassigndate, 'YYYY/MM/DD') as originatorassigndate,
                 zbd.description as description,
                 zbc.comments as comments
            FROM (SELECT obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM awdbt1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM mart1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM mpsdt1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM nondt1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM rnast1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM rnlht1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM rnolt1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM rzptt1m4.cmPrRpIt@TCPROD

    it's the tablename in the hint, not the column name
    something like
    SELECT ec.obid AS prObid,
                 ec.b2ProgramName AS program,
                 ec.projectName AS project,
                 ec.wbsID AS prNo,
                 ec.wbsName AS title,
                 ec.revision AS revision,
                 ec.superseded AS revisionSuperseded,
                 ec.lifeCycleState AS lifeCycleState,
                 ec.b2ChangeType AS type,
                 ec.b2Complexity AS subType,
                 ec.r1SsiCode AS ssi,
                 ec.b2disposition as disposition,
                 ec.wbsOriginator AS requestor,
                 ec.wbsAdministrator AS administrator,
                 ec.changepriority as priority,
                 ec.r1tsc as tsc,
                 ec.t1comments as tenixComments,
                 ec.b2securityclass as securityClassification,
                 ec.t1changesafety as safety,
                 ec.t1actionofficer as actionOfficer,
                 ec.t1changereason as changeReason,
                 ec.t1wbsextchangenumber as extChangeNo,
                 ec.creator as creator,
                 to_date(substr(ec.creationdate,
                                0,
                                instr(ec.creationdate, ':', 1, 3) - 1),
                         'YYYY/MM/DD-HH24:MI:SS') as creationdate,
                 to_date(ec.originatorassigndate, 'YYYY/MM/DD') as originatorassigndate
            FROM (SELECT /*+ DRIVING_SITE(awdbt1m4.cmPrRpIt) */ obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM awdbt1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT /*+ DRIVING_SITE(mart1m4.cmPrRpIt) */ obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM mart1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT /*+ DRIVING_SITE(mpsdt1m4.cmPrRpIt) */ obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM mpsdt1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT /*+ DRIVING_SITE(nondt1m4.cmPrRpIt) */ obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM nondt1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT /*+ DRIVING_SITE(rnast1m4.cmPrRpIt) */ obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM rnast1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT /*+ DRIVING_SITE(rnlht1m4.cmPrRpIt) */ obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM rnlht1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT /*+ DRIVING_SITE(rnolt1m4.cmPrRpIt) */ obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM rnolt1m4.cmPrRpIt@TCPROD
                  UNION
                  SELECT /*+ DRIVING_SITE(rzptt1m4.cmPrRpIt) */ obid,
                         b2ProgramName,
                         projectName,
                         wbsID,
                         wbsName,
                         revision,
                         superseded,
                         lifeCycleState,
                         b2ChangeType,
                         b2Complexity,
                         r1SsiCode,
                         b2disposition,
                         wbsOriginator,
                         wbsAdministrator,
                         changepriority,
                         r1tsc,
                         t1comments,
                         b2securityclass,
                         t1changesafety,
                         t1actionofficer,
                         t1changereason,
                         t1wbsextchangenumber,
                         creator,
                         creationdate,
                         originatorassigndate
                    FROM rzptt1m4.cmPrRpIt@TCPROD) ec(not tested, of course)

  • Using parameters in a select query sometimes not working

    I use parameters throughout my code - usually without problem, but for some reason in one case it does not return a result. When I modify the querystring to contain the value instead of using parameters it works. Is it because I'm secting a clob? or is it because I'm using a 9i ODP.net dll against a 10g database? this is c# 2.0
    here's the source code that does not work for me - REQUEST_DATA is a clob:
        public String loadRequest(String PSRNumber)
            String returnVal = null;
            ConnectionStringSettings connectionInfo = System.Configuration.ConfigurationManager.ConnectionStrings["Scribe"];
            OracleConnection myConnection = new OracleConnection();
            String strSQL = "select PSR, REQUEST_DATA from stats.request where PSR = :PSR";
            try
                myConnection.ConnectionString = connectionInfo.ConnectionString;
                OracleCommand cmd = new OracleCommand(strSQL, myConnection);
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.Add("PSR", OracleDbType.Varchar2).Value = PSRNumber;
                myConnection.Open();
                OracleDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                    returnVal = dr.GetOracleString(dr.GetOrdinal("REQUEST_DATA")).ToString();
                else
                    returnVal = null;
                dr.Dispose();
                cmd.Dispose();
            catch (OracleException ex)
                printError(ex.Message);
            finally
                myConnection.Close();
                myConnection.Dispose();
            return returnVal;
        }when I replace the line generating the sql, and remove the lines pertaining to parameters it works:
    String strSQL = String.Format("select PSR, REQUEST_DATA from stats.request where PSR = {0}", PSRNumber);
    I'm fine just using this as a workaround, but I need an explanation why the other does not work - I prefer to use parameters.
    Message was edited by:
    user633546

    I figured it out. thank you for your help in pointing me in the right direction.
    the problem was there was a trailing space in the data.
    when the data for that table is numeric for every record, the query allows me to leave out the single quotes. Trailing spaces do not seem to cause the database to see it as non-numeric - leaving out the quote still finds the record even if there is a trailing space.
    but when I put in the quote, it is not an exact string match, so it could not find the record. sometimes this flexibility gets me into trouble :\

  • DB Adapter : How to limit number parent records in select query.

    Hi All,
    I am querying a master-detail tables from a database.
    I want to limit the number of parent records to 15.
    Ex: Resources is parent table. It has two child tables "Skills" & "PersonalDetails".
    Resources table has 1 to many relationship with above tables.
    When i use rownum <= 15 in the where clause i am seeing different results each time.
    Sample query is as below.
    select distict t0.resourceName , t1.skillName , t2.location
    from .table_names
    where .....join between tables..
    and rownum <= 15
    Note : I selected the checkbox "Use outer joins to return a single result set for both master and detail tables" in DBAdapter wizard.
    Let me know if i am missing anything important.
    Thanks,
    Sid.

    Hi,
    You can set the "Max Rows" at the DBAdapter wizard ("Advanced Options" step).
    Regards,
    Daniel

  • 2 set of conditions to use in a Single Select query in procedure

    Good day
    I have one procedure, want to use one 2 set of conditions in Where clause
    like
    where condition1 < value
    AND condition 2 > value
    AND condition 3 = value
    where condition 1 > value
    AND condition 2 < value
    AND condition 4 = value
    How we should combine in a single select statement where cluase.
    Please accept my sincere thanks first and looking your advice asap.
    Regards
    M.K.Thamaraiselvan

    Hi,
    While we use this procdure to run at that time it is not picking up any values also it is not running in it, taking very long time.What is not picking the value? Where clause is not picking the value, or
    where clause is picking the value but you are not getting the output.
    If it is you are not getting the output.
    I suggest to run the sql query individually without pl/sql and check if the records actually exist.
    Since it is taking very long time, I feel the sql query is actually being executed in the database but could be you are not getting the records (check if records actualy exist or if you are correctly passing the where clause)
    Regards
    Anurag
    PS:
    v_sql_string := 'SELECT table/viewname.colomn_name,'||v_order_by||','||v_report_line ||','||
    v_output_line||',table/viewname.check_amount'||v_from_clause||v_where_clause||' ORDER BY '||v_order_by;So you are using dynamic sql, can you add an extra line
    dbms_output.put_line(v_sql_string);
    and check what the actual query is formed by pl/sql, if you are satisified the query is correct run it through sql plus and check why oracle does not give the result. MAy be there is no records satisfiying this condition. And I am sure you meant either table or viewname in (table/viewname.colomn_name) and not something like what you posted.
    Edited by: Anurag Tibrewal on Oct 8, 2009 9:15 AM

  • Use of Indexes in select query

    Hello,
    This is on a 9i install.
    There is an index called form_id_idx on the form_id column.
    Why does this query use the index (autotrace indicates range scan on the index):
    select count(*) from table_name where form_id=123456;
    but this query does NOT use the index (autotrace indicates full table scan):
    select accepted from table_name where form_id=123456;
    This second query runs much faster when I use a hint on the index. Any help/suggestions?
    Thanks.

    The first query does NOT have to go to the Table it all. It can read the index to count the number of rows for "form_id=123456". An Index Range Scan would be fast.
    The second query has to go to the table to get the values for the "accepted" column for all the rows that have "form_id=123456". Remember that every get can require a read of 2 or more blocks -- at least one, probably 2 or 3, from the index and 1 from the table. If the number of rows is likely to be large then the number of block get operations would be high. In such cases, Oracle computes that it is faster to do a small set of multiblock reads to read the whole table (Table FullScan).
    Therefore, the optimzer weighs :
    a. how many rows it thinks will satisfy "form_id=123456"
    b. how many index + table block gets it would have to execute (all as single block read calls to the OS)
    versus
    x. how many multiblock read calls it thinks it has to execute to read the whole table
    If the available statistics on number of rows, cardinality or density and the size of the table indicate that operation "x" would be cheaper then operations "a" + "b", Oracle would prefer the latter.
    Hemant K Chitale
    http://hemantoracledba.blogspot.com

  • Using command button to select query - WAD 7.0

    Hello all
    Can anyone please tell me how to configure a command button (button group) to display a particular query in WAD 7.0?
    Here's what I mean -
    I have a web template with three queries. I have inserted 3 command buttons on the template. I want to assign one button to one query, so that the users can select which of the three they want to view. Which Command do I select in the command wizard to do this? Also, is it possible to hide the other two queries, when one is selected?
    Thanks
    Karen

    Hi,
    Here is one approach - Keep three analysis items in the WT. Assign three different data providers to all three analysis items. If you do not want to show any query when the WT first loads, don't assign any query to the data providers. When a button is pushed, you can use the command SET_DATA_PROVIDER_PARAMATERS to assign a query to a DP so that that query will show up.
    Other commands that will help you would be SET_ITEM_PARAMETERS using which you can hide analysis items and also, you can use the command BACK_TO_INITIAL_DP_STATE on data providers so that they do not show up if they were blank at the start.
    Another way to hide a query is to assign the analysis item to a data provider which is blank.
    For your requirements, you will have to put multiple commands behind each button - you can decide which of the above commands suit you best.

  • Runtime error using range table in select query

    I have to select tcodes from table tstc, based on the entries in ust12,
    the entries in ust12-von and ust12-bis, these contains wild charcters also,  and i have to selct all the tcodes  from von to bis.
    so ia m preparing a range table for the entries in ust12, and querying table tstc, then i am getting a runtime error with following description.
    'If the problem occurred because an excessively large table was used
    in an IN itab construct, you can use FOR ALL ENTRIES instead.'
    but how can i use FOR ALL ENTRIES here, because if von = A* and bis = AB*,then i ahve to read all the entries from AAAA till ABZZ (may be something like this),
    is there any way to write this query, with out runtime error.
    there are total 15000 entries in ust12, i am preparing range table for 3000 entries each and querying tstc.
    Thanks in advance
    Best Regards
    Amarender Reddy B

    Hi,
    first write a select on ust12 based on ust12-von and ust12-bis.
    eg: select von bis from ust12 into table gt_ust12
                               where von LIKE 'A%'
                                   and bis LIKE 'AB%'.
    now write another select for tstc for all entries in gt_ust12...
    Hope it helps
    Regards,
    Pavan

  • Using this (~) symbol in select query ?what does this mean?

    Suppose
    SELECT   mapl~vbeln INTO IT_TAB mean what? also is this obsolete practice or still existing?
    Thank you for your time and answers in advance !

    It is used when alias name is used instead of actual table name. You don't have to use join in order to use alias.
    See ABAP Keyword Documentation and this:
    DATA lv_cityfrom TYPE spfli-cityfrom.
    SELECT SINGLE cityfrom FROM spfli AS a 
      INTO lv_cityfrom WHERE a~carrid EQ 'AA'.
    IF sy-subrc EQ 0.
      WRITE lv_cityfrom.
    ENDIF.

Maybe you are looking for

  • Using multiple ipods on itunes...

    Currently, my husband and I both have classic iPods and iPhones. We each have our own iTunes accounts on our laptops and run them separately. We have a very large CD collection which we have been backing up on an external hard drive. What would be th

  • FM or Tcode for No.of days employee attended Training in HR ABAP

    Hi Experts, I need to calculate No.of Days employee attended training in given payroll period level. For ex, iam giving 01.2010 FY (Payroll Period 21.04.2010 to 20.05.2010) . Need to find out how many days each employee under traning during this peri

  • Query base multiple levels  PO approval procedure

    Hi, My customer is having following requirement for PO approval procedure and would like to seek for solution. The suppliers are either CAPEX or OTHERS supplier which I think of using UDF U_CAPEXSUPPLIER=Y or N in BP master setup. OTHERS supplier PO

  • Server Does not start after backup complition

    Dear All, We are facing following problem some times after backup completion. Our Setup is : SAP ECC 6, Oracle 10g, HP-UX 11.31. We are scheduling the whole database offline + archive log backup during night. After completion of backup the SAP does n

  • ISE 1.1.1 cisco-av-pair:Wireless-WCS

    Hello, Has anyone configured ISE yet to authenticate WCS against ISE using RADIUS?  I have created the Authorization Profiles with rule0=SuperUsers, tack0=...ect, but I am wondering how everyone has done the authentication and authorization rules.  A