Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

how to count number of rows in a table column Expand / Collapse
Author
Message
Posted Wednesday, April 30, 2008 9:30 AM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Thursday, November 13, 2014 9:38 AM
Points: 759, Visits: 659
Hi all,
can any one send me the query to find the number of rows for a particular column,
thanks
Post #493075
Posted Wednesday, April 30, 2008 10:13 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, May 29, 2012 11:22 AM
Points: 1,755, Visits: 4,652
Nicole (4/30/2008)
Hi all,
can any one send me the query to find the number of rows for a particular column,
thanks

You have a terminology problem here, so it's hard to understand the question.

Rows aren't parts of table columns; rows are parts of tables.

Perhaps you mean one of these?

select count(Column) from Table
select count(distinct Column) from Table

Post some example data and the result you'd want for that example.



Ryan Randall

Solutions are easy. Understanding the problem, now, that's the hard part.
Post #493111
Posted Wednesday, April 30, 2008 10:24 AM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Thursday, November 13, 2014 9:38 AM
Points: 759, Visits: 659
Thanks,
I guess you are right, I thought of somthing else. I have a table and my manager wants to update that column, so he asked me to tell how many rows will be affected in that column of a table when we are updating it. He want me to say the number of rows for that column, and you are right rows count for a table is same for the column.
Post #493115
Posted Wednesday, April 30, 2008 10:58 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 4:31 PM
Points: 14,000, Visits: 28,381
You can get that specific count for your manager one of two ways. Safely:
SELECT COUNT(*)
FROM MyTable
WHERE MyColumn = 'OldValue'

Or not so safe:
BEGIN TRAN
UPDATE MyTable
SET MyColumn = 'NewValue'
WHERE MyColumn = 'OldValue'
ROLLBACK TRAN

The first query will return the count. The second query will return the number of rows affected, but it won't do anything. However, you are mucking with the data, just rolling it back, so you will put a load on the system. It's not as safe.


----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server Query Performance Tuning
SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #493131
Posted Wednesday, April 30, 2008 11:17 AM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Thursday, November 13, 2014 9:38 AM
Points: 759, Visits: 659
Thanks Grant Fritchey,
It helped me a lot. I have a problem in creating a view for my production db, i cannot post it here, if you can help me pls give me your email id, Its really critical for me to safe my job.

Thanks again.
Post #493143
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse