SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


how to count number of rows in a table column


how to count number of rows in a table column

Author
Message
ALIF-662928
ALIF-662928
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1849 Visits: 768
Hi all,
can any one send me the query to find the number of rows for a particular column,
thanks
RyanRandall
RyanRandall
SSCarpal Tunnel
SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)

Group: General Forum Members
Points: 4089 Visits: 4652
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.
ALIF-662928
ALIF-662928
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1849 Visits: 768
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.
Grant Fritchey
Grant Fritchey
SSC Guru
SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)

Group: General Forum Members
Points: 94547 Visits: 33010
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 and SQL Server Execution Plans
Product Evangelist for Red Gate Software
ALIF-662928
ALIF-662928
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1849 Visits: 768
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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search