Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Server INLIST ()
Message
 
To
04/11/2006 05:08:38
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01166962
Message ID:
01167297
Views:
8
Here a function for SQL Server
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
Previous
Reply
Map
View

Click here to load this message in the networking platform