Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Equivalent of VFP INLIST with string of values
Message
 
À
27/11/2007 15:50:13
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01271536
Message ID:
01271783
Vues:
24
Charles

I don't know if you have a working answer yet. Below is a function you can build in your data base, and then call it from within a query such as:

lcDeptList='1,2,3,4'
sqlexec(gnConnHandle,[exec prt_schedule ?p1,?p2,?p3,?lcDeptList])
CREATE PROCEDURE dbo.prt_Schedule
@ltQueryFrom datetime,
@ltQueryTo dateTime,
@tiDeptID int,
@tcDeptList varchar(1000)

as
select * from dbo.myTable 
where  dbo.myTable.DeptID in (select val from dbo.inlist(@tcDeptList))
Function Code
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform