Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Something like INLIST()
Message
 
À
26/06/2008 10:53:07
Jay Johengen
Altamahaw-Ossipee, Caroline du Nord, États-Unis
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01326940
Message ID:
01326952
Vues:
24
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))
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform