I am not sure how to best describe what I am trying to do (or search for it for that matter) but I am going to try.
I have a pre-existing query (stored procedure) that returns items based on 3 specific ID's. What I want to do is to be able to reduce the results even further based upon a column within the results having the exact same string. I want the query to return the count of items where a certain column has the exact same values within it.
For some reason I am confused about how to do this, I am drawing a complete blank about this.
Here a sample of the current data:
PROGRAMID DAY TIMESLOT SlotInfoDescription TITLE
2688 4 13:00-16:30 Free Time NULL
2688 4 16:30-17:10 NULL Joint Session with Search Engines: Machine Learning for Social Media Analytics
2689 4 13:10-16:00 Free Time NULL
2689 4 16:30-17:10 NULL Joint Session with Search Engines: Machine Learning for Social Media Analytics
2300 4 12:00-13:30 Free Time
2300 4 16:30-17:10 NULL Joint Session with Search Engines: Machine Learning for Social Media Analytics
Here are the results I want (based on Title being the same):
count = 1
Here is the current query:
SELECT
WS.PROGRAMID,
WS.ITEMID,
WS.DAY,
CASE datepart(weekday, dateadd(day, WS.DAY - 1, WE.EVENTSTARTDATE))
WHEN 1 THEN 'Sun'
WHEN 2 THEN 'Mon'
WHEN 3 THEN 'Tue'
WHEN 4 THEN 'Wed'
WHEN 5 THEN 'Thu'
WHEN 6 THEN 'Fri'
WHEN 7 THEN 'Sat'
ELSE 'N/A'
END
+ ' ' + Convert(char(12), dateadd(day, WS.DAY - 1, WE.EVENTSTARTDATE), 101) as Date,
WS.TIMESLOT,
WS.SLOTTYPE,
WSSTC.DESCRIPTION AS SlotTypeDescription,
WS.SLOTINFO,
WSSIC.DESCRIPTION AS SlotInfoDescription,
ISNULL(WSI.TALKID, 0) AS TalkID,
LEFT(WPI.FIRSTNAME, 10) + ' ' + LEFT(WPI.LASTNAME, 10) + ' (' + LEFT(WEA.INSTITUTION, 10) + ')' + ' - ' + LEFT(WSI.TITLE, 10) + '...' + RIGHT(WSI.TITLE, 10) AS Talk,
WPI.FIRSTNAME,
WPI.LASTNAME,
WEA.INSTITUTION,
WSI.AUTHORLINE,
WSI.TITLE,
LEFT(WSI.ABSTRACT, 1) AS Abstract,
WS.LOCATION,
WS.ADDENDUM
FROM
DBO.WEBSPEAKERINFO WSI
INNER JOIN
DBO.WEBPERSONALINFO WPI
ON
WSI.USERID = WPI.USERID
INNER JOIN
DBO.WEBEVENTAFFILIATION WEA
ON
WPI.USERID = WEA.USERID
AND
WEA.EVENTID IN @EVENTID
RIGHT OUTER JOIN
DBO.WEBSCHEDULESLOTTYPECODES WSSTC
RIGHT OUTER JOIN
DBO.WEBSCHEDULES WS
ON
WSSTC.SLOTTYPE = WS.SLOTTYPE
ON
WSI.TALKID = WS.TALKID
LEFT OUTER JOIN
DBO.WEBSCHEDULESLOTINFOCODES WSSIC
ON
WS.SLOTINFO = WSSIC.SLOTINFO
INNER JOIN
DBO.WEBEVENTS WE
ON
WE.EVENTID IN @EVENTID
WHERE
WS.PROGRAMID IN @EVENTID
AND
WS.DAY = @DAY
ORDER BY
DAY,
TIMESLOT