Table function: CREATE FUNCTION MultiList_to_tbl (@list nvarchar(MAX)) RETURNS @tbl TABLE (NrDilu nvarchar(20) NOT NULL) AS BEGIN DECLARE @pos int, @nextpos int, @valuelen int SELECT @pos = 0, @nextpos = 1 WHILE @nextpos > 0 BEGIN SELECT @nextpos = charindex(',', @list, @pos + 1) SELECT @valuelen = CASE WHEN @nextpos > 0 THEN @nextpos ELSE len(@list) + 1 END - @pos - 1 INSERT @tbl (NrDilu) VALUES (substring(@list, @pos + 1, @valuelen)) SELECT @pos = @nextpos END RETURN END Pouziti (ukazka je z me realne DB): Poslu tam pole napr. INT (1,2,3) z parametru @Revize prevedene do nvarchar(MAX), protoze predem neznam max. delku a ikdyz je to INT, funguje to bez problemu CREATE PROCEDURE [dbo].SP_LoadAuditByRevize ( @Revize nvarchar(MAX) ) AS SELECT ID_Audit, Typ_Zmeny, Zmenil_Audit, Datum_Zmeny FROM Tbl_Doc15_Audit JOIN MultiList_to_tbl(@Revize) i ON Tbl_Doc15_Audit.Revize_Nr_Audit = i.NrDilu
|