Count distinct a combination of two columns

Hi all,

I am trying to produce a report giving a number of unique clicks using the userID and ipAddress column of a table. i.e I only want to count unique values of userid and ip address.

I cant use count(disctinct userID, ipAddress) as syntax error. My sp is below:

Can anyone help?

CREATE PROCEDURE usp_afapply_periodReport
      @afid            varchar(20),
      @dateFrom       datetime,
      @dateTo      datetime


SELECT prodTypeID As [Product Type], prodID As [ProductID], COUNT (prodID) As [Total Applys],  COUNT(DISTINCT userID) As [Unique Applys]

FROM applyTracking

WHERE hitDate >= @dateFrom AND hitDate <= @dateTo
      affiliateID = @afid
      ipAddress != ''
      ipAddress NOT IN (SELECT ipAddress FROM affiliateIPs WHERE afid =  @afid )

GROUP BY prodTypeID, prodID

ORDER BY prodTypeID, prodID



Who is Participating?
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.

Would this work with your data?

SELECT prodTypeID AS [Product Type], prodID AS [ProductID], COUNT(prodID) AS [Total Applys],
COUNT(DISTINCT CAST(userID AS char(10)) + ipAddress) AS [Unique Applys]

FROM applyTracking

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
fevsterAuthor Commented:

Ive tried that and it brings back no results, so it isnt working.

fevsterAuthor Commented:
Actually sorry this does work, thanks thats great. userID was of type int and ipaddress varchar.

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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.