Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 6th, 2006, 02:08 PM
Registered User
 
Join Date: Jan 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Rowcount from SQL query

I need to know the count of how many rows a query is going to return
without actully bringing back all the data to my pc. I know I can use
select count(*) to find how many rows are in a table, but I need to
know how many rows are going to be returned in a complicated query
that has joined multiple tables without actually running the query and
returning the total results because it will be around one million and
many columns. I realize I have to run it to get the number of
rows it will return but I don't want all the columns and rows to come
back as a result. Just the count. For example a query might be:

(select one, two, three, four, five <-- How many rows from this ?
from table1, table2, table3,
where etc, etc, etc.)

I want the count of how many rows will be returned from the query, not a single table. I don't have sqlserver enterprise edition to use the analyzer, I just thought there might be a way of including this whole query between parenthises with some way to bring back just the count. Any ideas?
 
Old January 6th, 2006, 02:31 PM
Authorized User
 
Join Date: Sep 2005
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

select count(*)
from table1, table2, table3,
where etc, etc, etc.)

example

select count(*) from employee e join address a on e.id =a.id
where zipcode = 10288

“I sense many useless updates in you... Useless updates lead to fragmentation... Fragmentation leads to downtime...Downtime leads to suffering..Fragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" -- http://sqlservercode.blogspot.com/
 
Old January 6th, 2006, 02:50 PM
Registered User
 
Join Date: Jan 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I get an error when I try that. Then it doesn't like the "." thats used for the table qualifier. I get ther error "-104, ERROR: ILLEGAL SYMBOL ".". SOME SYMBOLS THAT MIGHT BE LEGAL ARE: , FROM INTO (0.07 secs)"
My query looks like this:

SELECT count (*)
         dbc.VVVT_TBRSLTS_CODE, dbc1.AUTH_CLNT_IDNO,
         dbc1.AUTH_PREVSTOP_DATE, dbc2.ACTV_CLNT_IDNO,
         dbc2.ACTV_PRVDTYPE_CODE, dbc2.ACTV_BILLSTAT_CODE,
         dbc3.PROF_STAE_CODE, dbc3.PROF_ZIP_CODE, dbc3.PROF_PHON_NUMB,
         dbc3.PROF_CNTY_CODE
FROM SCHCVVVT.dbcYVAUTH01 dbc1,
         SCHCVVVT.dbcYVvVVT01 dbc,
         SCHCVVVT.dbcYVACTV01 dbc2,
         SCHCVVVT.dbcYVPROF01 dbc3
WHERE dbc1.AUTH_CLNT_IDNO=dbc.VVVT_CLNT_IDNO
AND dbc2.ACTV_CLNT_IDNO=dbc.VVVT_CLNT_IDNO
AND dbc2.ACTV_PRVD_IDNO=dbc3.PROF_IDNO

 
Old January 6th, 2006, 02:57 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

try this...

SELECT count (*)
FROM dbcYVAUTH01 dbc1,
         dbcYVvVVT01 dbc,
         dbcYVACTV01 dbc2,
         dbcYVPROF01 dbc3
WHERE dbc1.AUTH_CLNT_IDNO=dbc.VVVT_CLNT_IDNO
AND dbc2.ACTV_CLNT_IDNO=dbc.VVVT_CLNT_IDNO
AND dbc2.ACTV_PRVD_IDNO=dbc3.PROF_IDNO


HTH

Gonzalo
 
Old January 6th, 2006, 02:59 PM
Authorized User
 
Join Date: Sep 2005
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

SELECT count (*)
         FROM SCHCVVVT.dbcYVAUTH01 dbc1,
         SCHCVVVT.dbcYVvVVT01 dbc,
         SCHCVVVT.dbcYVACTV01 dbc2,
         SCHCVVVT.dbcYVPROF01 dbc3
WHERE dbc1.AUTH_CLNT_IDNO=dbc.VVVT_CLNT_IDNO
AND dbc2.ACTV_CLNT_IDNO=dbc.VVVT_CLNT_IDNO
AND dbc2.ACTV_PRVD_IDNO=dbc3.PROF_IDNO


“I sense many useless updates in you... Useless updates lead to fragmentation... Fragmentation leads to downtime...Downtime leads to suffering..Fragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" -- http://sqlservercode.blogspot.com/
 
Old January 6th, 2006, 04:08 PM
Registered User
 
Join Date: Jan 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That works. Thanks a lot.






Similar Threads
Thread Thread Starter Forum Replies Last Post
sql query i need seearam MySQL 7 November 30th, 2008 03:14 AM
Output Query to txt file from SQL Query everest SQL Server 2005 4 November 22nd, 2007 01:49 AM
Find the rowcount before blank cell stepdev Excel VBA 6 May 22nd, 2006 03:05 PM
SQL Query mcinar SQL Language 2 March 1st, 2005 10:16 PM
Assigning a @@ROWCOUNT to a variable ioates SQL Server DTS 2 January 9th, 2004 04:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.