Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Something like INLIST()
Message
 
To
26/06/2008 10:53:07
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01326940
Message ID:
01326952
Views:
23
Jay


I use this function:
CREATE FUNCTION DBO.Inlist (@list varchar(8000))
 RETURNS @tbl TABLE (val int not null, Ord int not null)  AS  
 BEGIN 
        Declare @index int,
                @pos int,
                @str varchar(8000),
                @num int
        Set @pos = 1
        Set @index = 1
        While @index > 0
        Begin
                set @index = charindex(',', @list, @pos)
                if @index > 0
                        Set @str = substring(@list, @pos, @index - @pos)
                Else
                        Set @str = substring(@list, @pos, Len(@list))
                     Set @str = ltrim(rtrim(@str))
                Set @num = cast(@str as integer)
                Insert @tbl (val,ord) values (@num,@pos)
                Set @pos = @index + 1
        End
        Return
 End
Example Call:
declare @tcDeptList varchar(200)
set @tcDeptList = '123,124,175,198'

SELECT dbo.meetings.begintime, 
dbo.meetings.endtime, 
dbo.meetings.sdatetime
dbo.coRooms.Roomname

FROM  	dbo.meetings (nolock) INNER JOIN
        dbo.corooms (nolock) ON dbo.meetings.roomid = dbo.corooms.roomid
where dbo.meetings.RoomID in (select val from dbo.inlist(@tcDeptList))
Previous
Reply
Map
View

Click here to load this message in the networking platform