Count() function to count the records in specific column in Sql server 2008

Hi,

I have a table with 10 columns, and i am doing a count on selected columns.
SELECT count 
	([User_Emp_ID], [User_ID], [User_Name],
	[Reviewer_ID], [High_Privileged], [Certifiable], [Bypass_Termination])
from OIA_Data_Load
GO

Open in new window


But i am geting an error
Msg 174, Level 15, State 1, Line 4
The count function requires 1 argument(s).

Open in new window


Also, in my table, i have  column called Count. I want this column to count the no. of rows in these specified columns, and get displayed at the end of the column.
msrblr4Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TempDBACommented:
you can't specify more then 1 columns in count() function. You can do it by
SELECT count (*)
from OIA_Data_Load
GO
0
Christopher GordonSenior Developer AnalystCommented:
Write a subquery to get the distinct record count.  Then do a count off of that subquery.

SELECT count(*) 
(	
	select distinct 

	[User_Emp_ID], [User_ID], [User_Name],
	[Reviewer_ID], [High_Privileged], [Certifiable], [Bypass_Termination]
	
	from OIA_Data_Load	
) distinct_fields

GO

Open in new window

0
tim_csCommented:
Can you give an example of what your data looks like and what your expected results are?

Are you looking to see which fields have values?
0
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

DALSOMCommented:
Hi, try this :

select field1,field2,fieldn,count(*) as fieldcount
from mytable
where <myfilters>
group by field1,field2,fieldn

In this way, you will count only your "group by" fields.

0
msrblr4Author Commented:
I have attached the file for your reference.
I have shown the columns, which need a count on them, and at the end, i have another column named "Record_Count".
The script should only count the total no. of records which are higlighted in Green, and display them at the end of the "Record_Count" column *(as shown in the xls file).

Any script for this, would be good, so that i can add it into my existing SP.
OIA-Data.xls
0
SickSkilzCommented:
Just do it with a subquery
select count(*) from
(select blaa blaa blaa from blaa)

This way you can get counts of distinct members across different fields for isntance.
0
DALSOMCommented:
You will have the 24 repeated as many rows is counting for record_count field. Not only for last one.
But you can supress at your program where you need to show your query results.

I hope this help, but, you really have all good answers from everyone posted here! ;)

0
msrblr4Author Commented:
Actually, i wrote the script and it looks like this;
SELECT User_Emp_ID, User_ID, User_Name,
	Reviewer_ID, High_Privileged, Certifiable, Bypass_Termination, count(*) AS Record_Count
	from OIA_Data_Load
	GROUP BY 
	GROUPING SETS 
	(
		(User_Emp_ID, User_ID, User_Name,
		Reviewer_ID, High_Privileged, Certifiable, Bypass_Termination), () 
	)
GO

Open in new window

This gives me the result outside the table. i.e. it fetches the records and displays the total record counts.
How do i update the same, which will update my table and the records in them, and shows me the final result......
0
SickSkilzCommented:
so here it is

select  User_Emp_ID, Application_Role,User_ID,User_Name,Reviewer_ID,      High_Privileged,Certifiable, Bypass_Termination, count(*) as Record_Count

That would show in the last column a count would would represent the number of records specific to a distinct combination of all the green column fields.
0
DALSOMCommented:
Try this, hope this really helps you find your answer :

create table #alldates(dt datetime)
declare @dd int
set @dd = 1
insert into #alldates values(GETDATE())
while @dd <= 1000
begin
      insert into #alldates values(DATEADD(dd,(@dd*-1),getdate()))
      set @dd = @dd + 1
end

create table #invoices(invoiceno int not null,inv_date datetime,amount money,sold bit)
insert into #invoices values(1,'2011-12-25',100,0)
insert into #invoices values(2,'2011-12-25',200,0)
insert into #invoices values(3,'2011-12-22',100,0)
insert into #invoices values(5,'2011-12-21',100,0)
insert into #invoices values(8,'2011-12-20',100,0)


select d.dt as [Invoice Date],COUNT(i.inv_date) as [Invoice counts]
from #alldates d left outer join #invoices i on year(d.dt) = year(i.inv_date)
      and MONTH(d.dt) = MONTH(i.inv_date) and DAY(d.dt) = DAY(i.inv_date)
where YEAR(d.dt) = 2011 and MONTH(d.dt) = 12 and DAY(d.dt) >= 20
group by d.dt


Check the group by, count field and joins.
And of course, the results.
By the way,
Merry C.
Dalsom
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
msrblr4Author Commented:
Not really up to the acceptance level, but i got what i want.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.