Tune query on dual table.

Hello,
I am using ORACLE 11g and RHEL 5.
I have a performance tuning issue.
One of the query which returns the output in 0.016 seconds i.e. the below one
select to_number((sysdate- to_date('1970-01-01 00:00:00','YYYY-MM-DD HH24:MI:SS')) * 86400 -
((substr(TZ_OFFSET(sessiontimezone),1,
instr(TZ_OFFSET(sessiontimezone),':')-1) * 3600)+((substr(TZ_OFFSET(SESSIONTIMEZONE),
(instr(TZ_OFFSET(sessiontimezone),':')+1), 2)*60)))) TIME_STAMP ,
to_number(to_char(systimestamp,'FF')) MICROSEC
from dualI want to optimize this query at such a extend that it should give the output in less than 10 microseconds
now this query returns the output in 0.016 seconds...which is way to more as per the need.
I can also adjust if the output time is constant all the time....
for ex:-
if the query returns the output in 15 microsecond when fired for the first time then it should return the output in 15 microsecond for all the consequential execution. If the query gets executed for 10 times then i should get the output in 15 microsecond for all the 10 times.
can anyone guide me how to tune this query to get the output in less than 10 microsecond ???
else
how can i execute this query to return the output in the same time at every execution ???
Thanks in advance ...

Hi,
VJ4 wrote:
can anyone guide me how to tune this query to get the output in less than 10 microsecond ???I don't think it is possible using a (disk based) database. Their purpose is not to measure time but to serve and manipulate relational data.
As far as i know, <10µs will be hard to achieve.
Maybe TimesTen IMDB (InMemoryDataBase) can do that...
but wouldn't warranty the constant exec time.
VJ4 wrote:
how can i execute this query to return the output in the same time at every execution ???Well, I don't think you can. The Oracle database is not real-time. The execution time will higly depends on several factors, like parsed query still in shared pool, database server not being too charged, etc...
More over : assuming the query will always execute at exactly the same "speed" in order to measure how fast you are processing unit is not a good idea, as it assumes your unit processing speed is constant.
I think you should try to explain the big picture, and how you came to decide you need a query that return in less than 10µs.
Tell us why you cannot just execute it one in a while, and do the usual math :
processing speed = ("units processed at T2" - "units processed at T1") / (T2 - T1)

Similar Messages

  • Sql query and dual table

    Hi,
    1. Do dual table take any physical space in the database or it is only logically present?
    2. Suppose a table contains 100 rows. Write a query to return 42,43,44 rows.
    Thanks,
    Mrinmoy

    user3001930 wrote:
    Hi,
    1. Do dual table take any physical space in the database or it is only logically present?Dual table is physically stored. But starting from 10g (I guess) they indroduced the FAST DUAL access path. Which means if you use the DUAL table not to get the value from the table and only to select a constant value then it will not hit the actually table.
    2. Suppose a table contains 100 rows. Write a query to return 42,43,44 rows.You can use the analytic function ROW_NUMBER for this purpose.

  • Query from DUAL

    I am calling a Pl/sql function in a select query which has a statement as below
    SELECT SUBSTR(5/2,2,1) INTO m_delim FROM DUAL;
    The number of records returned from the calling select query is more 1 million.
    How much adversly the query from DUAL table affects the performance of the select query?

    user557052 wrote:
    I am calling a Pl/sql function in a select query which has a statement as below
    SELECT SUBSTR(5/2,2,1) INTO m_delim FROM DUAL;
    The number of records returned from the calling select query is more 1 million.
    How much adversly the query from DUAL table affects the performance of the select query?Even if you are selecting from dual, querying once would be enough based on your select statement.
    It does not seem like it is varying, you are trying to find the delimiter, which can be done once.
    Ss

  • Use of addImageTheme method with dual table in query

    Is it possible to specify a query using the dual table that specifies a BLOB type? I'm trying to specify a image theme dynamically using the bean API. My image is a JPEG.

    Hi Jen,
    if you create a table with a BLOB to store the image, plus a geometry column with the image MBR, then you can easily build the dynamic image theme using the API. Your SQL on the image theme would be something like: select mbr, image from image_table.
    I'm not sure if there is a direct function at the SQL level that takes an image file and generates a BLOB. Maybe someone has done something similar. If this function exists, then you may be able to create an image theme issuing a SQL with dual table.
    Joao

  • How to use one query against multiple table and recieve one report?

    I have duplicate tables, (except for their names of course) with commodities prices. They have the same column headings, but the data is different of course. I have a query that gives me a certain piece of information I am looking for but now I need to run this query against every table. I will do this every day as well, to see if the buying criteria is met. There are alot of tables though (256). Is there a way to say run query in all tables and return the results in one place? Thanks for your help.

    hey
    a. the all 256 tables whuld be one big partitoned table
    b. you can use all_tables in order to write a select that will write the report for you:
    SQL> set head off
    SQL> select 'select * from (' from dual
      2  union all
      3  select 'select count(*) from ' || table_name || ' union all ' from a
      4  where table_name like 'DB%' AND ROWNUM <= 3
      5  union all
      6  select ')' from dual;
    select * from (
    select count(*) from DBMS_LOCK_ALLOCATED union all
    select count(*) from DBMS_ALERT_INFO union all
    select count(*) from DBMS_UPG_LOG$ union all
    remove the last 'union all', and tun the generated quary -
    SQL> set head on
    SQL> select * from (
      2  select count(*) from DBMS_LOCK_ALLOCATED union all
      3  select count(*) from DBMS_ALERT_INFO union all
      4  select count(*) from DBMS_UPG_LOG$
      5  );
      COUNT(*)
             0
             0
             0
    Amiel

  • Doubt in DUAL TABLE

    Hi,
    below is one query
    SQL> select * from dual;
    D
    XNow from the below Query I came to know that there is one field in the dual table DUMMY which is having VARCHAR2(1)
    SQL> desc dual;
    Name                                                  Null?    Type
    DUMMY                                                          VARCHAR2(1)now my doubt is when I run the below query how it is displaying text more than 1 character
    SQL> select 'how are you' from dual;
    'HOWAREYOU'
    how are youplease explain
    thanks in advance.

    Hi,
    What you are SELECTing here nas no relation to any column in the table.
    There's nothing special about the dual table regarding literals. Try
    SELECT  'Hello'
    FROM    scott.dept;Notice that scott.dept does not have any 5-character columns, yet a query on scott.dept is producing a 5-character column.
    When you query a table, you don't have to SELECT all of the columns in the table. In fact, you don't have to SELECT any of the columns in the table, as you demonstrated.
    The query you posted, like the query above, does not refer to any columns in its base table; it's not surprising that the output doesn't resemble any column in the base table. In the case of the query above, which is based on a table that has 3 columns, the one column that we are SELECTing can't have the characteristics of all 3 columns in the table. Which column do you think the output should resemble, and why? 'Hello' is the first column of output; does that mean it has to resemble the first column in the table, which happens to be defined as NUMBER (2)? 'Hello' is also the last column of output; does that mean it has to resemble the last column of the table? 'Hello' is directly in the center of the output; does that mean it has to resemble the column that happens to be in the middle of the table? Of course not!
    Once agian, it is perfectly legal, and sometimes extremely useful, to have columns in a result set that have no connection at all to any column in the table.

  • Select query on a table with 13 million of rows

    Hi guys,
    I have been trying to perform a select query on a table which has 13 millions of entries however it took around 58 min to complete.
    The table has 8 columns with 4 Primary keys looks like below:
    (PK) SegmentID > INT
    (PK) IPAddress > VARCHAR (45)
    MAC Address > VARCHAR (45)
    (PK) Application Name > VARCHAR (45)
    Total Bytes > INT
    Dates > VARCHAR (45)
    Times > VARCHAR (45)
    (PK) DateTime > DATETIME
    The sql query format is :
    select ipaddress, macaddress, sum(totalbytes), applicationname , dates,
    times from appstat where segmentid = 1 and datetime between '2011-01-03
    15:00:00.0' and '2011-01-04 15:00:00.0' group by ipaddress,
    applicationname order by applicationname, sum(totalbytes) desc
    Is there a way I can improve this query to be faster (through my.conf or any other method)?
    Any feedback is welcomed.
    Thank you.
    Mus

    Tolls wrote:
    What db is this?
    You never said.
    Anyway, it looks like it's using the Primary Key to find the correct rows.
    Is that the correct number of rows returned?
    5 million?
    Sorted?I am using MySQL. By the way, the query time has been much more faster (22 sec) after I changed the configuration file (based on my-huge.cnf).
    The number of rows returned is 7999 Rows
    This is some portion of the my.cnf
    # The MySQL server
    [mysqld]
    port = 3306
    socket = /var/lib/mysql/mysql.sock
    skip-locking
    key_buffer = 800M
    max_allowed_packet = 1M
    table_cache = 256
    sort_buffer_size = 1M
    read_buffer_size = 1M
    read_rnd_buffer_size = 4M
    myisam_sort_buffer_size = 64M
    thread_cache_size = 8
    query_cache_size= 16M
    log = /var/log/mysql.log
    log-slow-queries = /var/log/mysqld.slow.log
    long_query_time=10
    # Try number of CPU's*2 for thread_concurrency
    thread_concurrency = 6
    Is there anything else I need to tune so it can be faster ?
    Thanks a bunch.
    Edited by: user578505 on Jan 17, 2011 6:47 PM

  • Dbms_xmlgen.newcontext query from multiple tables and ||

    I have two questions
    How do I get a dbms_xmlgen.context to query from multiple tables? I have been able to make it work with using one table only, but not with multiple tables.
    And how to get the || (concat) to work within my query for my output to an xml file?
    Here is my current query:
    create or replace function get_xml return clob is
    result clob;
    qryctx dbms_xmlgen.ctxHandle;
    SELECT DBMS_XMLGEN.getxml('select prefix, suffix, fiscal_yr
    FROM rcv.recv_accessions ra
    where ra.prefix = 8 and ra.fiscal_yr = 11')xml into result FROM dual;
    result := DBMS_XMLGEN.getXML(qryCtx);
    This is what I desire:
    SELECT DBMS_XMLGEN.getxml('select ra.prefix||'-'|| ra.suffix||'-'|| ra.fiscal_yr accession, ss.date_in, st.test
    FROM rcv.recv_accessions ra, ser.sero_samples ss, ser.sero_tests st
    where ra.prefix = 8 and ra.fiscal_yr = 11 and ss.raid = ra.id and st.ssid = ss.id')xml into result FROM dual;
    On this both the reference to multiple tables and the concat function cause errors.
    Thank you
    Edited by: user583094 on Mar 2, 2011 3:36 PM

    Hi,
    for the concat do I use xmlconcat?No, XMLConcat is used to concatenate XMLType fragments.
    The || operator will do fine, but you must escape any single quote inside the string :
    SELECT DBMS_XMLGEN.getxml(
    'SELECT ra.prefix ||''-''|| ra.suffix ||''-''|| ra.fiscal_yr as accession,
            ss.date_in,
            st.test
    FROM rcv.recv_accessions ra,
          ser.sero_samples ss,
          ser.sero_tests st
    WHERE ra.prefix = 8
    AND ra.fiscal_yr = 11
    AND ss.raid = ra.id
    AND st.ssid = ss.id'
    INTO result
    FROM dual;Or, use the quoting operator to define a custom string delimiter :
    SELECT DBMS_XMLGEN.getxml(
    q'{SELECT ra.prefix ||'-'|| ra.suffix ||'-'|| ra.fiscal_yr as accession,
            ss.date_in,
            st.test
    FROM rcv.recv_accessions ra,
          ser.sero_samples ss,
          ser.sero_tests st
    WHERE ra.prefix = 8
    AND ra.fiscal_yr = 11
    AND ss.raid = ra.id
    AND st.ssid = ss.id
    INTO result
    FROM dual;BTW, a good practice would be to use bind variables for the query. DBMS_XMLGEN can handle them nicely :
    CREATE OR REPLACE FUNCTION get_xml
    RETURN CLOB
    IS
    qryctx   DBMS_XMLGEN.ctxHandle;
    v_out    CLOB;
    qrystr   VARCHAR2(4000) :=
    'SELECT ra.prefix ||''-''|| ra.suffix ||''-''|| ra.fiscal_yr as accession,
            ss.date_in,
            st.test
    FROM rcv.recv_accessions ra,
          ser.sero_samples ss,
          ser.sero_tests st
    WHERE ra.prefix = :b_prefix
    AND ra.fiscal_yr = :b_fiscal_yr
    AND ss.raid = ra.id
    AND st.ssid = ss.id';
    BEGIN
    qryctx := DBMS_XMLGEN.newContext(qrystr);
    DBMS_XMLGEN.setBindValue(qryctx, 'b_prefix', '8');
    DBMS_XMLGEN.setBindValue(qryctx, 'b_fiscal_yr', '11');
    -- to generate empty elements if necessary :
    DBMS_XMLGEN.setNullHandling(qryctx, DBMS_XMLGEN.EMPTY_TAG);
    v_out := DBMS_XMLGEN.getXML(qryctx);
    DBMS_XMLGEN.closeContext(qryctx);
    RETURN v_out;
    END;

  • DUAL Table problem

    As a quick way to grant privileges to almost all the objects in my schema to a role, i created a procedure (Courtesy of user CD from Oracle Forums). But when i executed the below mentioned procedure i got the error :
    ORA-01720: grant option does not exist for 'SYS.DUAL'
    To avoid granting privileges to sys.dual, I tried adding AND OBJECT_NAME < > 'SYS.DUAL' and AND OBJECT_NAME < > 'DUAL' to the query. But that this didn't help.
    But when i query SELECT * FROM DUAL; i can see that DUAL table exists in my schema.
    Any thoughts?
    Here is what i did
    CREATE ROLE newrole;
    DECLARE
    v_sql VARCHAR2(4000);
    BEGIN
    FOR obj IN (SELECT object_name
    , object_type
    , DECODE (OBJECT_TYPE,
    'PROCEDURE','EXECUTE',
    'FUNCTION' ,'EXECUTE',
    'PACKAGE' ,'EXECUTE',
    'SYNONYM' ,'SELECT' ,
    'SEQUENCE' ,'SELECT' ,
    'MATERIALIZED VIEW','SELECT',
    'SELECT, INSERT, UPDATE, DELETE') rights
    FROM user_objects where object_type IN
    ('FUNCTION','PROCEDURE','PACKAGE','SYNONYM','SEQUENCE','MATERIALIZED VIEW','TABLE','VIEW'))
    LOOP
    v_sql := 'GRANT ' || obj.rights || ' ON ' || obj.object_name || ' TO NEWROLE';
    dbms_output.put_line(v_sql);
    EXECUTE IMMEDIATE v_sql;
    END LOOP;
    END;
    /

    One of your views must reference DUAL, perhaps indirectly.
    If this comes up again you can create an exception to catch the error inside the loop for the current item and continue. Not pretty, but it should work something like (untested)
      for record in cursor loop
        --block to catch exception
        declare
           my_error exception;
          --substitute proper error number for -000001 below
          pragma exception_init(-000001,my_error)
        begin
        exception
          when my_error then
            null;
        end;
        --continue processing with next loop item   
      end loop;

  • Silly question on dual table

    Hello gurus
    This dual table is a dummy table with varchar2(1)....my question is how it can select many psedocolumns from dual doesn't it exceed the allowed space of varchar2(1)
    Edited by: 964145 on Oct 9, 2012 5:35 PM

    >
    it cannot be a real table
    >
    Not sure why you say that.
    The DDL for it is in the dcore.bsq file (11.2) in the rdbms/admin folder
    create table dual    /* pl/sql's standard pckg requires dual. */
      (dummy varchar2(1))    /* note, the optimizer knows sys.dual is single row */
      storage (initial 1)
    insert into dual values ('X')
    /See the SQL Language doc
    http://docs.oracle.com/cd/B28359_01/server.111/b28286/queries009.htm#SQLRF20036
    >
    Selecting from the DUAL Table
    DUAL is a table automatically created by Oracle Database along with the data dictionary. DUAL is in the schema of the user SYS but is accessible by the name DUAL to all users. It has one column, DUMMY, defined to be VARCHAR2(1), and contains one row with a value X. Selecting from the DUAL table is useful for computing a constant expression with the SELECT statement. Because DUAL has only one row, the constant is returned only once. Alternatively, you can select a constant, pseudocolumn, or expression from any table, but the value will be returned as many times as there are rows in the table. Refer to "About SQL Functions" for many examples of selecting a constant value from DUAL.
    >
    And the Database Concepts doc
    http://docs.oracle.com/cd/B28359_01/server.111/b28318/datadict.htm
    >
    The DUAL Table
    The table named DUAL is a small table in the data dictionary that Oracle Database and user-written programs can reference to guarantee a known result. This table has one column called DUMMY and one row containing the value X.
    >
    And those pseudo-columns you ask about
    >
    select sysdate,UID,rowid from dual;
    >
    You can query those from any table but as the doc quote above says you will get as many values as there are rows in the table.

  • Using sql query as a table name

    hello,
    I have a table(say table1) which is storing the names of some other tables. I want to access the name of a table from table1 using sql query and then use the result of this query as the table name to access the data from
    retrieved table name. How can I do this ?
    ex:
    select * from (select tablename from table1 where tableid='1');
    I want to do something likw this. How can I do this?

    I want to access the name of a table from table1 using sql query and then use the result of this query as the table name to access the data from retrieved table name. How can I do this ?e.g. like this:
    SQL> with table1 as (
    select 'emp' tablename from dual
    select extractvalue(x.column_value, 'ROW/ENAME') ename
    from table1, xmltable('ROWSET/ROW' passing dbms_xmlgen.getxmltype('select * from ' || tablename)) x
    ENAME                                                                                                                       
    SMITH                                                                                                                       
    ALLEN                                                                                                                       
    WARD                                                                                                                        
    JONES                                                                                                                       
    MARTIN                                                                                                                      
    BLAKE                                                                                                                       
    CLARK                                                                                                                       
    SCOTT                                                                                                                       
    KING                                                                                                                        
    TURNER                                                                                                                      
    ADAMS                                                                                                                       
    JAMES                                                                                                                       
    FORD                                                                                                                        
    MILLER                                                                                                                      
    14 rows selected.

  • Avoid Hard Parsing for executing dynamic SQL using DUAL table Oracle

    I want to know if dynamic sql statements involving DUAL table can be modified to remove HARD PARSING.
    We have several SQL statements are stored in configuration table, here is sample example
    -- query 1 before replacing index values as stored in config table ---
    select count(*) from dual where  'REPLACE_VALUE_OF_INDEX_3' IN ('K')
    AND (('REPLACE_VALUE_OF_INDEX_13' IN ('1053','1095','1199') ) OR ('REPLACE_VALUE_OF_INDEX_13' IN ('1200') ))
    AND 'REPLACE_VALUE_OF_INDEX_2' IN ('6')
    AND 'REPLACE_VALUE_OF_INDEX_15' IN ('870001305')
    -- query 1 after replacing index values--
    select count(*) from dual where  'REPLACE_VALUE_OF_INDEX_10' IN ('K')
    AND (('1030' IN ('1053','1095','1199') ) OR ('1030' IN ('1200') ))
    AND '2' IN ('6')
    AND 'X' IN ('870001305')
    -- query 2 before replacing index values as stored in config table --
    select count(*) from dual where  'REPLACE_VALUE_OF_INDEX_5' IN ('361A','362A')
    AND 'REPLACE_VALUE_OF_INDEX_22' BETWEEN '200707' AND '200806'
    -- query 2 after replacing index values--
    select count(*) from dual where  '3MAA' IN ('361A','362A') AND '201304' BETWEEN '200707' AND '200806'

    If I got it right you have some (maybe lots of) conditions stored in a table (be patient - it's my interpretation)
    create table eb_conditions as
    select 1 rid,q'{:5 IN ('361A','362A') AND :3 BETWEEN '200707' AND '200806'}' cndtn from dual union all
    select 2,q'{:2 IN ('361A','362A') AND :3 BETWEEN '200707' AND '200806'}' from dual union all
    select 3,q'{:1 IN ('K') AND ((:2 IN ('1053','1095','1199') ) OR (:4 IN ('1200') )) AND :3 IN ('6') AND :5 IN ('870001305')}' from dual
    RID
    CNDTN
    1
    :5 IN ('361A','362A') AND :3 BETWEEN '200707' AND '200806'
    2
    :2 IN ('361A','362A') AND :3 BETWEEN '200707' AND '200806'
    3
    :1 IN ('K') AND ((:2 IN ('1053','1095','1199') ) OR (:4 IN ('1200') )) AND :3 IN ('6') AND :5 IN ('870001305')
    and you have to check the conditions using values stored in an array
    I used a table instead: the vl at rid = 1 representing the value of bind variable :1 in eb_conditions table and so on ...
    create table eb_array as
    select 1 rid,'K' vl from dual union all
    select 2,'1199' from dual union all
    select 3,'200803' from dual union all
    select 4,'1000' from dual union all
    select 5,'870001305' from dual
    RID
    VL
    1
    K
    2
    1199
    3
    200803
    4
    1000
    5
    870001305
    You want to check the conditions using select count(*) from dual where <condition with binds substituted fron the array>
    Judging from the title Hard Parsing represents the major problem and you cannot avoid it since every condition to be verified is different from every other condition.
    I think your best bet is not to evaluate conditions row by row - context shift cannot be avoided and there might be more than one for each iteration.
    So try to do it in a single step:
    declare
    w_cndtn varchar2(4000);
    w_clob  clob;
    w_cursor sys_refcursor;
    one number;
    two number;
    begin
      dbms_lob.createtemporary(w_clob,false);
      for rw in (select rid,
                        max(cndtn) cndtn,
                        listagg(val,',') within group (order by rn)||',' usng
                   from (select c.rid,c.cndtn,c.rn,c.bind,
                                replace(rtrim(c.bind),':'||to_char(v.rid),''''||v.vl||'''') val
                           from (select rid,
                                        cndtn,
                                        regexp_substr(cndtn,':\d+ ',1,level) bind,
                                        level rn
                                   from eb_conditions
                                 connect by level <= regexp_count(cndtn,':')
                                        and prior rid = rid
                                        and prior sys_guid() is not null
                                ) c,
                                eb_array v
                          where instr(c.bind,':'||v.rid||' ') > 0
                  group by rid
      loop
        w_cndtn := rw.cndtn;
        while instr(w_cndtn,':') > 0
        loop
          w_cndtn := replace(w_cndtn,trim(regexp_substr(w_cndtn,':\d+ ',1,1)),substr(rw.usng,1,instr(rw.usng,',') - 1));
          rw.usng := substr(rw.usng,instr(rw.usng,',') + 1);
        end loop;
        w_cndtn := 'select '||to_char(rw.rid)||' cndtn_id,count(*) from dual where '||w_cndtn||' union all ';
        w_clob := w_clob ||' '||w_cndtn;
      end loop;
      w_clob := substr(w_clob,1,instr(w_clob,'union all',-1,1) - 1);
      open w_cursor for w_clob;
      loop
        fetch w_cursor into one,two;
        exit when w_cursor%notfound;
        dbms_output.put_line(to_char(one)||':'||to_char(two));
      end loop;
      dbms_lob.freetemporary(w_clob);
    end;
    1:0
    2:0
    3:0
    Statement processed.
    Regards
    Etbin

  • How to use dual table in ODI in source side for nested queries?

    Hi,
    Any idea how to use dual table in source for more than once. I want to build a ODI interface for the following source query
    SELECT ACTV_TYP.ACTV_TYP_SRC_CD, ACTV_TYP.ACTV_TYP, PORT_ACTV_TYP.PORT_ACTV_TYP_SRC_CD, PORT_ACTV_TYP.PORT_ACTV_TYP, SFT_DLT_STS.SFT_DLT_STS_SRC_CD, SFT_DLT_STS.SFT_DLT_STS
    FROM
    SELECT LOW_VALUE PORT_ACTV_TYP_SRC_CD, MEANING PORT_ACTV_TYP
    FROM CUSTOMS.DOMAIN_ALLOW_COLUMNS_VALUES
    WHERE TABLE_NAME = 'BRKR_PORTS'
    AND COLUMN_NAME = 'WORK_PORT_TYPE') PORT_ACTV_TYP,
    (SELECT LOW_VALUE SFT_DLT_STS_SRC_CD, MEANING SFT_DLT_STS
    FROM CUSTOMS.DOMAIN_ALLOW_COLUMNS_VALUES
    WHERE TABLE_NAME = 'BANKS'
    AND COLUMN_NAME = 'REC_STATUS') SFT_DLT_STS,
    (SELECT 1 ACTV_TYP_SRC_CD, '?????' ACTV_TYP FROM DUAL
    UNION ALL
    SELECT 2 ACTV_TYP_SRC_CD, '???????' ACTV_TYP FROM DUAL) ACTV_TYP
    Regards

    If the below query is equivalent , it seems you don't need dual table at all , just default the values in the interface.
    You are using dual tables to populate values ACTV_TYP.ACTV_TYP_SRC_CD, ACTV_TYP.ACTV_TYP values. Look at your query in the following manner :
    SELECT '1', '?????', PORT_ACTV_TYP.PORT_ACTV_TYP_SRC_CD, PORT_ACTV_TYP.PORT_ACTV_TYP, SFT_DLT_STS.SFT_DLT_STS_SRC_CD, SFT_DLT_STS.SFT_DLT_STS
    FROM
    SELECT LOW_VALUE PORT_ACTV_TYP_SRC_CD, MEANING PORT_ACTV_TYP
    FROM CUSTOMS.DOMAIN_ALLOW_COLUMNS_VALUES
    WHERE TABLE_NAME = 'BRKR_PORTS'
    AND COLUMN_NAME = 'WORK_PORT_TYPE') PORT_ACTV_TYP,
    (SELECT LOW_VALUE SFT_DLT_STS_SRC_CD, MEANING SFT_DLT_STS
    FROM CUSTOMS.DOMAIN_ALLOW_COLUMNS_VALUES
    WHERE TABLE_NAME = 'BANKS'
    AND COLUMN_NAME = 'REC_STATUS') SFT_DLT_STS
    UNION
    SELECT 2 , '??????', PORT_ACTV_TYP.PORT_ACTV_TYP_SRC_CD, PORT_ACTV_TYP.PORT_ACTV_TYP, SFT_DLT_STS.SFT_DLT_STS_SRC_CD, SFT_DLT_STS.SFT_DLT_STS
    FROM
    SELECT LOW_VALUE PORT_ACTV_TYP_SRC_CD, MEANING PORT_ACTV_TYP
    FROM CUSTOMS.DOMAIN_ALLOW_COLUMNS_VALUES
    WHERE TABLE_NAME = 'BRKR_PORTS'
    AND COLUMN_NAME = 'WORK_PORT_TYPE') PORT_ACTV_TYP,
    (SELECT LOW_VALUE SFT_DLT_STS_SRC_CD, MEANING SFT_DLT_STS
    FROM CUSTOMS.DOMAIN_ALLOW_COLUMNS_VALUES
    WHERE TABLE_NAME = 'BANKS'
    AND COLUMN_NAME = 'REC_STATUS') SFT_DLT_STS
    Now you can use dataset to make UNION.

  • Run a query on linked tables to create a new datasource

    Using Crystal XI
    I have a report that draws from two data sources.  They can't be joined at the server side, but they are linked in Crystal Database Expert. 
    I can't figure out if Crystal gives me a way to write an SQL Query to run an aggregate function referencing both tables.  The results of this query would be the datasource for a graph in the report.  I'm wondering if Crystal gives me a way, maybe through subreports, to write the query I need.
    More concretely:
    And I want to include in my datasource alarmId, Hour and the Maximum amount of calls received in any one hour for any one station (this maximum is to provide scale for a graph)
    In one table nameed AlarmStartTimes I have data like
    Alarms
    AlarmID  Hour    Recipient
    Alarm1       8       Joe
    Alarm23  10      Mark
    Alarm60  7      Joe
    Alarm95  8      Linda
    In another I have data like
    EELocation
    Recipient   Location
    Joe         Station1
    Mark         Station2
    Linda          Station1
    So if I could just join my talbes at the server side I'd use a query like:
    select *, max(select count(AlarmID) from Alarms, EELocation from Alarms Join EELocationo on Alarms.Recipient=EELocation.Recipient group by Hour, Location) AS  from Alarms
    Anyway, that's probably got a syntax error or 4 in it, but you get the idea.
    I can't group on the database side.  Since Crystal is able to link the two tables and successfully group them out by Location, it seems like there should be some way for me to run a query against the tables reflecting that existing link, but I can't see how to do it.
    The reason I can't link on database side is that the data is in two databases, and it's not known what the location of the databases is at report-writing time.  The location of the databases gets set via the Crystal API when the report is launched from an application.

    Since you have 2 datasource in the report you are limited on what you can use in crystal, such as crystal will not allow you to use sql expressions.

  • How to get save result from EXECUTE from a dynamic SQL query in another table?

    Hi everyone, 
    I have this query:
    declare @query varchar(max) = ''
    declare @par varchar(10)
    SELECT @par = col1 FROM Set
    declare @region varchar(50)
    SELECT @region = Region FROM Customer
    declare @key int
    SELECT @key = CustomerKey FROM Customer
    SET @query = 'SELECT CustomerKey FROM Customer where ' + @par + ' = '+ @key+ ' '
    EXECUTE (@query)
    With this query I want get col1 from SET and compare it to the column Region from Customer. I would like to get the matching CustomerKey for it.
    After execution it says commands are executed successfully. But I want to save the result from @query in another table. I looked it up and most people say to use sp_executesql. I tried a few constructions as sampled and I would always get this error: 
    Msg 214, Level 16, State 2, Procedure sp_executesql, Line 12
    Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'.
    So the output should be a list of CustomerKeys in another table.
    How can I save the results from EXECUTE into a variable? Then I assume I can INSERT INTO - SELECT in another table. 
    Thanks

    CREATE TABLE Customer
    (CustomerKey INT , Name NVARCHAR(100));
    GO
    INSERT dbo.Customer
    VALUES ( 1, N'Sam' )
    GO
    DECLARE @query nvarchar(max) = ''
    declare @par varchar(10) = 'Name',
    @key varchar(10) = 'Sam'
    CREATE TABLE #temp ( CustomerKey INT );
    SET @query =
    insert #temp
    SELECT CustomerKey
    FROM Customer
    where ' + @par + ' = '''+ @key+ ''' '
    PRINT @query
    EXEC sp_executesql @query
    SELECT *
    FROM #temp
    DROP TABLE #temp;
    DROP TABLE dbo.Customer
    Cheers,
    Saeid Hasani
    Database Consultant
    Please feel free to contact me at [email protected] as well as on Twitter and Facebook.
    [My Writings on TechNet Wiki] [T-SQL Blog] [Curah!]
    [Twitter] [Facebook] [Email]

Maybe you are looking for

  • [xfce4] - removing options from "open with" submenu [SOLVED]

    Since installing wine, I have a number of entries in my right-click>open with menu that are similar to "Wine - Internet Explorer."  I'd like to remove these.  Any tips are appreciated. Last edited by graysky (2011-12-10 16:03:42)

  • How to send images into another panel

    hi i got two panels and one panel creates a couple of images and the confusing thing is that i don't want that panel to display my images but i want the other side panel to display these images.. but i don't know how to do it. actually i can create t

  • Outbound Dialer records to cache. how does it work?????

    Im confused, on the campaign manager one of the settings for the campaigns is Records to cache.  The Outbound guide says that this is "the minimum number of dialing numbers that each dialer caches for each of your outbound option skill groups.  Defau

  • IPhoto Trash won't empty

    I just realized my iPhoto Trash won't empty. When I click on it the software crashes. There are about 800 images in the Trash. I tried restoring about half of them to their albums and then emptying Trash -- but same thing -- Crash. Any suggestions? T

  • Change Document - Block Invoice for Payment - BAPI

    Hello All, I have the requirement to block an invoice for payment through the Portal. In FB02 transaction, we can select an item and set the "Payment Block" indicator to B (blocked) for instance. I would like to know if exists a BAPI that allows this