Passing string data into a function for use in IN clause
Posted on 2003-03-09
I'm working on a calendar component that has different categoryies for the events on the calendar. I need to be able to select all, or some of the categories when displaying the calendar. I have a function written that should do this:
GetCalData(DispDate datetime, CalendarID int, CategoryIDs varchar(100))
and what I'd like to do is put something like 4,12,16,20,25 in the CategoryIDs variable and enclose that in an IN, similar to:
SELECT * FROM Events WHERE (CalendarID = @CalendarID) AND (EventDate BETWEEN @DispDate AND DateAdd(m,1,@DispDate)) AND (CategoryID IN(4,12,16,20,25))
(I don't have the exact code in front of me so please forgive any syntactical errors [ie, with DateAdd])
I can't seem to get this to work because the CategoryID is an interger field in the database. Does anyone have any ideas as to how I'd do this? I'm trying to avoid limiting the number of Category's allowed to be displayed, and think I've tried everything.
Thank you very much.