|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Tuesday, October 16, 2012 10:42 AM
Points: 759,
Visits: 613
|
|
Hi all, can any one send me the query to find the number of rows for a particular column, thanks
|
|
|
|
|
SSCommitted
      
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.
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Tuesday, October 16, 2012 10:42 AM
Points: 759,
Visits: 613
|
|
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.
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Yesterday @ 3:40 PM
Points: 13,380,
Visits: 25,164
|
|
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 2012 Query Performance Tuning SQL Server 2008 Query Performance Tuning Distilled and SQL Server Execution Plans
Product Evangelist for Red Gate Software
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Tuesday, October 16, 2012 10:42 AM
Points: 759,
Visits: 613
|
|
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.
|
|
|
|