Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 returns rows and count as one

Author  Topic 

dgaylor
Yak Posting Veteran

54 Posts

Posted - 2003-11-13 : 11:34:15
I have a situation where I need to select all of the rows in a table, and return the count of the rows in one line - I don't care that the same count will be repeated for each row. How can I do this, anything I try gives me an error? I would basically like to do the following:

select *, count(*) from sales

---------------------
CREATE TABLE [dbo].[sales] (
[rec_id] [int] IDENTITY (1, 1) NOT NULL ,
[sales_date] [char] (6) NULL ,
[sales_amount] [int] NULL
) ON [PRIMARY]
GO

Data:
insert sales (sales_date, sales_amount) values ('200301',50)
insert sales (sales_date, sales_amount) values ('200301',50)
insert sales (sales_date, sales_amount) values ('200302',150)

------------------
Thanks in advance.

nic
Posting Yak Master

209 Posts

Posted - 2003-11-13 : 11:46:41
Here you go


SELECT
*
,(SELECT COUNT(*) FROM Sales) AS Count
FROM
Sales


Nic
Go to Top of Page
   

- Advertisement -