i'm stuck!! i'm trying to determine if a customer attended our webinar based on their log in date/time - that's the easy part. but there are many customers who logged in several times, and using a case statement is not working the way i need it to. below is a snippet of my code:

case when jh.join_date BETWEEN DATEADD(mi,-45,web.START_DATE_TIME) and web.END_DATE_TIME then 'Attended' else 'Did Not Attend' end

and this works if a customer ONLY logged in during the specified times. however, if they logged in during the event AND logged in prior to or after the event, they will be listed multiple times. makes sense so far, except i need either/or. i've tried to re-write my query several times, but i'm not able to exclude those records that fall outside of the specified time.

danawexler (4/29/2013)i'm stuck!! i'm trying to determine if a customer attended our webinar based on their log in date/time - that's the easy part. but there are many customers who logged in several times, and using a case statement is not working the way i need it to. below is a snippet of my code:

case when jh.join_date BETWEEN DATEADD(mi,-45,web.START_DATE_TIME) and web.END_DATE_TIME then 'Attended' else 'Did Not Attend' end

and this works if a customer ONLY logged in during the specified times. however, if they logged in during the event AND logged in prior to or after the event, they will be listed multiple times. makes sense so far, except i need either/or. i've tried to re-write my query several times, but i'm not able to exclude those records that fall outside of the specified time.

thanks in advance for your help!

Hard to give you an answer based just on what you posted. Can you post the DDL for the table(s) involved, some sample data that mirrors your current data, the expected results, and what you have tried so far?

Lynn is absolutely correct that in order to give any solid advice we need a lot more details to work with. However, maybe I can give you a nudge that will help you. It seems that what you need to do is to put together a cte that has all the CustomerID values that were in attendance. Then you can query your customer table with a left join to your cte. If the cte value is NULL they did not attend, otherwise they did.

-- Set up sample data, this is a guess of what your current query results look like-- For the sake of this example webinar #45623 was from 10:00am to 10:30am-- and webinar #23178 was from 11:00am to 11:30amset language english;declare @query_results table (user_name nvarchar(10), event_id int, join_date datetime, attendance nvarchar(15));

-- The existing query is returning more than one line per user, -- but we only want to know if the user has attended the event.-- Write an aggregate query, taking care of which column(s) you need to group byselect q.user_name, q.event_id, min(attendance) as attendancefrom @query_results qgroup by q.user_name, q.event_id;

the problem i have is reflected in the below result set:CUSTOMER_ID JOIN_DATE AttendedWebinar000000033064 4/17/2013 4:28:18 PM Did Not Attend000000033064 4/18/2013 9:40:59 AM Attended

The result i need is either Attended or Did Not Attend, and i realize my query is working correctly as written - it needs to be tweaked to allow for one or the other.

As Lynn has already stated we need to see ddl and sample data. This means we need a script to create your table(s) and insert statement to populate them with data that represent your issue. Please take a few minutes and read the first article in my signature for best practices when posting questions.