views:

46

answers:

1

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
+1  A: 

Assuming you're using SQL Server. since you know what columns your stored proc returns you can do this:

create #tempTable ( columnsSprocReturns )
insert into #tempTable
exec yourSproc

select columns 
from   #tempTable
where  someColumn = 'someValue'

drop table #tempTable
Mladen Prajdic
I will try that, what does the columnsSprocReturns used for
mattgcon
the temp table should have the same column types as your sproc returns. something like (id int, col1 varchar(20)) etc. they HAVE TO match down to the length of the datatype.
Mladen Prajdic
Oh ok gotcha. But one thing I have to mention the where clause ('someValue') is not a given, I need to find out where they match
mattgcon
Ok I have this working however, within the where clause I need to be able to find all the items within the temptable where the rows have matching values within a certain column (the values are not known)
mattgcon
i don't see your problem. you know which columns to look in and somehow you have to know for which values you looking for so a simple where should be enough.
Mladen Prajdic