Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
asp_rin
Starting Member
4 Posts |
Posted - 2004-09-08 : 17:07:39
|
| oktable - dbo.ResearchDataReg9columns that contain the data needed = cliuniqueid, ticdatecliuniqueid = nvarchar 255 unique client identifier (can and does have repeated records)ticdate = smalldatetime 4 date that the client came in1. i need the distinct count of dates for each client2. then I need a distinct count of cliuniqueid where ticdate >= 6 display that andthen >= 11 display that andthen >= 16 etc right on down the list...if need more info just askif anyone can help that would be awesome I have been strugling with this for a few days I am new to SQL.. |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-09-08 : 17:23:36
|
| [code]DECLARE @MyTable TABLE (clientId int, inDate datetime)INSERT INTO @MyTable VALUES(1, '02/05/04')INSERT INTO @MyTable VALUES(2, '02/06/04')INSERT INTO @MyTable VALUES(3, '02/07/04')INSERT INTO @MyTable VALUES(1, '02/15/04')INSERT INTO @MyTable VALUES(1, '03/01/04')INSERT INTO @MyTable VALUES(3, '02/08/04')INSERT INTO @MyTable VALUES(3, '03/15/04')INSERT INTO @MyTable VALUES(2, '02/18/04')INSERT INTO @MyTable VALUES(3, '04/01/04')INSERT INTO @MyTable VALUES(1, '03/05/04')INSERT INTO @MyTable VALUES(3, '04/02/04')INSERT INTO @MyTable VALUES(3, '04/05/04')INSERT INTO @MyTable VALUES(1, '03/06/04')INSERT INTO @MyTable VALUES(1, '03/10/04')INSERT INTO @MyTable VALUES(3, '04/15/04')INSERT INTO @MyTable VALUES(1, '03/11/04')INSERT INTO @MyTable VALUES(1, '04/01/04')INSERT INTO @MyTable VALUES(3, '04/25/04')INSERT INTO @MyTable VALUES(1, '04/18/04')INSERT INTO @MyTable VALUES(1, '04/25/04')INSERT INTO @MyTable VALUES(3, '05/02/04')INSERT INTO @MyTable VALUES(1, '05/02/04')Insert Into @MyTableSelect clientId=4, inDate From @myTable where clientId = 3Select ClientId, count(distinct inDate) From @myTable Group By ClientIdSelect Range = convert(nvarchar,n * 5 + 1) + ' to ' + convert(nvarchar,(n+1) * 5), Cnt = Count(*)From ( Select ClientId, n=(count(distinct inDate)-1)/5 From @myTable Group By ClientId ) as AGroup By N[/code]Corey |
 |
|
|
asp_rin
Starting Member
4 Posts |
Posted - 2004-09-08 : 22:00:40
|
| thanks!I used partial code and created a view with it and used where clauses in my ASP to get the results |
 |
|
|
|
|
|
|
|