Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I think the forum is a great idea, especially for those of us in consulting engineering. Keep up the good work!..."

Geography

Where in the world do Tek-Tips members come from?
tipofapin (TechnicalUser)
19 Mar 12 13:44
Using SQL 2005 and  SSRS 2008 R2.  I have a list of clients who have had appointments within a date range.  So I have columns with Client name, appointment date and time, and Appt Kept (Y/N).  I need to return those who have consecutive no show appointments. That is for 2 or more appointments in a row, their 'Appt Kept' is 'N'.  Is there a way to do this?
xlbo (MIS)
20 Mar 12 20:04
I would be doing this in the SQL query

Effectively do 2 queries of the data with a rownumber partioned by client (i.e. restarts on change of client

assuming a simple table called Appointments with clientName, appt_date, Attended as the columns you can use:

CODE

SELECT * FROM Appointments
WHERE Client_Name IN
(
Select Distinct Client_Name
FROM
(SELECT c1.ClientName, c1.appt_date as dt1, c1.attended as Attended1, c2.Appt_Date as dt2, c2.Attended as Attended2
FROM
(SELECT Client_Name, Appt_date, Attended, row_number() over (partition by Client_Name order by Appt_Date as incr
 FROM Appointments
) c1
inner join
(SELECT Client_Name, Appt_date, Attended, row_number() over (partition by Client_Name order by Appt_Date as incr
 FROM Appointments
) c2
on c1.Client_Name = c2.Client_Name and c1.incr = c2.incr -1
) ConsecutiveMisses
where Attendd1 = 'N' and Attended2 = 'N'
)

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244: How to get the best answers before you ask a question

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close