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.
| 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]GOData: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 goSELECT * ,(SELECT COUNT(*) FROM Sales) AS CountFROM Sales Nic |
 |
|
|
|
|
|