Results 1 to 5 of 5
  1. #1
    Join Date
    May 2003
    Posts
    23

    Unanswered: SQL Query Help..

    Hi Friends,
    I am new to db2 database and trying to convert a sql statement that works fine on SQL-2000 into db2 database.

    Basically What I am trying todo is If I have two tables named table1 and table 2, I want to count the number of rows in these two tables and represent the results as two different coloumns in the result set. The following statement works fine for me in SQL server 2000. Can anyone tell me the equivalent db2 statement

    SELECT (SELECT COUNT(*) FROM Table1) AS Count1,
    (SELECT COUNT(*) FROM Table2) AS count2

    The resultset is a table with two coloumns Count1 and Count2 in it.

    Thanks,
    Sai

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650

    Re: SQL Query Help..

    See if this example helps :

    values((select count(*) from syscat.tables),(select count(*) from syscat.views))
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  3. #3
    Join Date
    May 2003
    Posts
    23

    Sql Query Help...

    Thanks for the reply.
    But when I try to execute this in db2 using strsql
    then it says,
    INTO clause missing from embedded statement.
    Am I doing something wrong ??

    -Sai

  4. #4
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650

    Re: Sql Query Help...

    If you are coding embedded SQL, every SELECT/FETCH statement should have the INTO Clause

    SELECT col1,col2 into :col1,:col2 from table1

    or
    FETCH Cursor1 into :col1,:col2

    Of course, SELECT Statement in a cursor defn is an exception

    (Pl check the syntax)

    Cheers
    Sathyaram


    Originally posted by saikrishna_dv
    Thanks for the reply.
    But when I try to execute this in db2 using strsql
    then it says,
    INTO clause missing from embedded statement.
    Am I doing something wrong ??

    -Sai
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  5. #5
    Join Date
    Jul 2002
    Posts
    21
    select (select count(*) from t1), (select count(*) from t2) from sysibm.sysdummy1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •