User Profile

Collapse

Profile Sidebar

Collapse
cburnett
cburnett
Last Activity: Jun 3 '10, 04:46 AM
Joined: Aug 1 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • cburnett
    replied to Concatenation in case of case expression
    in DB2
    I think this is what you are after (I have changed the column names to match the sample tables):

    Code:
    select '~#'|| firstnme||
           '~#'|| lastname||
           '~#'|| char(edlevel)|| 
           '~#'|| case edlevel when 16 then 'system engineer'
                               when 18 then 'senior engineer'
                               else         'unkonwn'
                  end      as string
     from em
    ...
    See more | Go to post

    Leave a comment:


  • cburnett
    replied to DB2 UDB 9.5 FP2a is not using the best index
    in DB2
    Could be that distribution stats are changing the optimizer's estimate.
    See more | Go to post

    Leave a comment:


  • The ORDER BY is easy as you can use
    Code:
    ORDER BY 1
    to sort by the first column.

    To get rid of the duplication completely, use the WITH clause:

    Code:
    WITH EVAL_TABLE(BUS_CHANNEL, DIVISION_NODE, DIVISION_NODE_NM, OWN_RESP_NODE_CD, NODE_NM, SRC_SYS_ACT_NO) AS (# SELECT
    # CASE
    #   WHEN SYS1.S1_CL_MG_ACT_D.OWN_RESP_NODE_CD IN
    #     ('D2192', 'D3155', 'D3211', 'D3212', 'D3213', 'D3214',
    #      'D3215', 'D3216',
    ...
    See more | Go to post

    Leave a comment:


  • Something like this should do the trick:
    Code:
    create table customer_purchases(customer_id   char(3) not null,
                                    purchase_date date    not null,
                                    vehicle_id    char(4) not null);
    commit;
    insert into customer_purchases values('C1', '2000-02-29', 'VIN1');
    insert into customer_purchases values('C1', '2000-05-26', 'VIN2');
    insert into customer_purchases
    ...
    See more | Go to post

    Leave a comment:


  • One thing sticks out here:

    DFT_QUERY_OPT=9

    This defaults to 5 which is usually an OK setting; 9 means the Optimizer will check out every possibility it can think of. Thus, if you have a lot of dynamic SQL (and you probably do, given Java), this will be chewing up a lot of elapsed (& CPU!) time.
    See more | Go to post

    Leave a comment:


  • cburnett
    replied to Querry Execution time
    in DB2
    Nimisha,
    You might want to check out the db2batch utility which ships with the product - it will give you this info.
    See more | Go to post

    Leave a comment:


  • cburnett
    replied to Getting Error sql0338n
    in DB2
    Tejas,
    I think you may be reading too much into my example. This is a setup and test to show the effect of the changes rather than a rewrite of your problem.

    For example, I'm not proposing any temporary tables; just a modificaiton of the SQL. Look particularly at lines 41-47 (of your original problem). I am proposing that you replace these lines with EITHER lines 56-62 OR lines 72-76, depending on whichever performs ...
    See more | Go to post

    Leave a comment:


  • cburnett
    replied to Getting Error sql0338n
    in DB2
    You might want to try the following approach:

    Code:
    -- using first 3 joins as an example
    create table join_is(h_num int not null, ph_ts timestamp not null);
    create table ad_ph(h_num int not null, ts timestamp not null, cmd_cd varchar(3) not null);
    create table ad_com(cmd_cd varchar(3) not null, ts timestamp not null, v_frm int not null);
    
    insert into join_is values(0, timestamp('2009-01-01 00:00:00'));
    ...
    See more | Go to post

    Leave a comment:


  • cburnett
    replied to MQT with MQT
    in DB2
    Oops. Freudian slip - I read this as MDC (Multi-dimensional Cluster) tables. For MQTs, you cannot create an MQT based on another MQT. The following sample code:

    Code:
    create table dept_sum(deptno,
                          employees,
                          total_salary) as
           (select workdept, count(*), sum(salary)
              from colin.employee
             group by workdept)
           data initially
    ...
    See more | Go to post

    Leave a comment:


  • cburnett
    replied to MQT with MQT
    in DB2
    Using the sample EMPMDC, I just successfully created one along the lines you suggest so looks like this is fine in DB2 also.

    Code:
    create table testmdc as (select empno, dept from colin.empmdc) data initially deferred refresh deferred
    See more | Go to post

    Leave a comment:


  • cburnett
    replied to Improving a SQL statement
    in DB2
    In general, I have found that the OLAP functions perform well in this regard. You might want to try something like the following sample code:

    Code:
    create table A(seq int, id char(1));
    insert into A values (1,'A');
    insert into A values (2,'B');
    insert into A values (3,'C');
    
    create table B(seq int, order int);
    insert into B values (1,1);
    insert into B values (1,2);
    insert into B values
    ...
    See more | Go to post

    Leave a comment:


  • cburnett
    replied to Return union result in one row?
    in DB2
    Code:
    select empno,
                  max(email) as email,
                  max(mgremail) as mgremail
         from (select empno, email , ' ' as mgremail
                       from emp_t
                     union all
                     select empno, ' ' as email, mgremail
                        from mgr_t) x
       group by empno
    See more | Go to post

    Leave a comment:


  • You might want to also include the clause OPTIMIZE FOR 21 ROWS at the end of the statement as well; this tells the optimizer that you only expect to to retrieve 21 rows (Yes I know that the FETCH 21 ROWS ONLY clause infers this, but worth a try anyway).
    See more | Go to post

    Leave a comment:


  • cburnett
    replied to DB2 on delete cascade is not working
    in DB2
    You've left out not null on column a1 for table A.

    Consequently alter pk fails and fk fails hence no delete cascade.
    See more | Go to post

    Leave a comment:


  • cburnett
    replied to DB2 Cpu Usage
    in DB2
    In these days of LPARS and multi-cores, the definition of CPUs can be fuzzy. Both CA and db2pd -osinfo report on the number of CPU cores. Thus, I surmise that you have 2 quad-core CPUs on your server (making total and configCPU = 8). Check by looking at the Cores/socket column which I believe will be 4 in your case.

    OnlineCPU = 4 would then mean that DB2 is only using 1 CPU. Why would this be so? Two possibilities come to mind....
    See more | Go to post

    Leave a comment:


  • Perhaps the easiest way is to turn the problem around:
    1. WHERE INT(ID_PERSOANA )=?
    2. EXECUTE PREPARED_STMT1 USING ID_TAX


    You can't use parameter markers in select lists or as table names but there's nothing stopping you building up the statement in the way you have.

    For the variable data type translation, look at the DIGITS function (integer to char with leading zeroes) or the CAST function. Note that with the...
    See more | Go to post

    Leave a comment:


  • UNION column names

    I'm afraid I know of no way of forcing this situation to occur for DB2 LUW.

    As for "fixing DB2", you might find the following two posts of interest:

    http://searchoracle.techtarget.com/e...264228,00.html

    http://it.toolbox.com/blogs/db2zos/i...mn-names-12556

    So it...
    See more | Go to post

    Leave a comment:


  • cburnett
    replied to Single Tablespace or Separate Tablespaces
    in DB2
    It's difficult to know without details of the workload. If the indexes and the data are being probed randonmly then having these in the same bufferpool is probably appropriate. If you are doing table or index scans then they may be better separated (so that the scan doesn't roll out the recently used pages).

    I'm assuming here you are on V9. If you are, then there is a good reason for defining the LONG data separately: FILE SYSTEM...
    See more | Go to post

    Leave a comment:


  • cburnett
    replied to retrieve all table names from DB2
    in DB2
    Retrieving tables

    Something like this is what you are after:
    Code:
    select rtrim(T.tabschema)||'.'||rtrim(T.tabname) as table_name
      from syscat.tables T 
      with ur
    See more | Go to post

    Leave a comment:


  • cburnett
    replied to Single Tablespace or Separate Tablespaces
    in DB2
    Single or Multi-tablespace

    It can do. If different tablespaces are used then different parameters can be assigned. E.g.Different buffer pool, page size, extent size etc. Bufferpool could be the main reason as the pages will be cahced in separate memory areas with this approach. Also, if the tables are large using a 32K page size for the indexspace can improve performance as more leaf pages can be contained in the pages (if LARGE...
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...