December 2, 2003 at 5:16 am
select count(DISTINCT
convert(nvarchar,DD.fk_intDocumentID)+ 'zzz' + convert(nvarchar,DD.fk_intUserID)
)
from dbo.tbl_DocumentDownloads DD
where ......
the above select statement counts the number of times a user downloads a document (not including repeat downloads of the same document, hence the DISTINCT keyword).
the presense of the zzz in the above statement is to avoid an error due to the combination of two numbers eg combining 23 and 67 would be the same as combining 2 and 367 thus yielding an error
all of this works fine but surely there must be a prettier way of doing this count????
Edited by - eamonroche on 12/02/2003 05:17:53 AM
December 2, 2003 at 5:34 am
I would guess that by putting
select DISTINCT DD.fk_intDocumentID ,DD.fk_intUserID
from dbo.tbl_DocumentDownloads DD
where ......
in a view and than counting the number of records in the view would be cleaner and faster too
Regards
Kurt - just waiting on a reply on my topic 😉
X
X
December 2, 2003 at 5:38 am
Suggestion:
select count(*) from
(
select 1 as Num
from dbo.tbl_DocumentDownloads DD
where ......
group by
DD.fk_intDocumentID,
DD.fk_intUserID
)as A
December 2, 2003 at 6:03 am
thanks davidt. works fine and looks more effiecient.
December 2, 2003 at 6:35 am
No Worries
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply