Re: Cursor vs Set - is it possible
From: keene (anonymous_at_discussions.microsoft.com)
Date: 04/06/04
- Next message: Adam Machanic: "Re: Cursor vs Set - is it possible"
- Previous message: mikew: "Re: xp_cmdshell right for non sysadmin"
- In reply to: Steve Z: "Cursor vs Set - is it possible"
- Next in thread: Adam Machanic: "Re: Cursor vs Set - is it possible"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 6 Apr 2004 13:16:06 -0700
Not sure what you want, really. but you may want to try a
subquery.
select count(*) from yourtable a
where exists(select * from yourtable b where
datediff(d,a.date,b.date)=1)
>-----Original Message-----
>I always try to use a SELECT and avoid CURSOR logic -
whenever possible - but this time I can't even think of a
way to SET-base this operation.
>
>I've got a table that stores dates of ATTENDANCE. Only
non-present dates have rows for a person.
>ABSENT on 04/02/2004 gets a row for a person - ABSENT
again on 04/07/2004 gets a row for a person.
>
>I want to create a UDF that returns the "consecutive
number" of ABSENT entries in this table for a person,
based on a starting date and going backwards.
>
>I could simply loop a working variable with a date and
do a SELECT to see if a record exists - then decrement
the date by one day and check again - that was the way we
did it on the mainframe VAX we are converting from...
>
>BTW - weekends and holidays are ignored - they don't
break the CONSECUTIVE counter...
>
>Any help would be greatly appreciated...
>.
>
- Next message: Adam Machanic: "Re: Cursor vs Set - is it possible"
- Previous message: mikew: "Re: xp_cmdshell right for non sysadmin"
- In reply to: Steve Z: "Cursor vs Set - is it possible"
- Next in thread: Adam Machanic: "Re: Cursor vs Set - is it possible"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|