If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > SQL Query Help..

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-11-03, 11:05
saikrishna_dv saikrishna_dv is offline
Registered User
 
Join Date: May 2003
Posts: 23
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
Reply With Quote
  #2 (permalink)  
Old 11-11-03, 11:10
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
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.
Reply With Quote
  #3 (permalink)  
Old 11-11-03, 11:26
saikrishna_dv saikrishna_dv is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 11-11-03, 11:38
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
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


Quote:
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.
Reply With Quote
  #5 (permalink)  
Old 11-14-03, 07:14
jay1972 jay1972 is offline
Registered User
 
Join Date: Jul 2002
Posts: 21
select (select count(*) from t1), (select count(*) from t2) from sysibm.sysdummy1
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On