Hi,
I have the following stored procedure:
CREATE PROCEDURE testingprocedure
(
@IDs VarChar(8000),
@DV int
)
AS
Declare @IdNumbers Table(Id Integer)
Insert
Into @IdNumbers(Id)
Select FieldName As Id from dbo.Split(@new_lettersID, ',')
SELECT
ID,
DATANAME,
DV
FROM
table_name
Inner Join @IdNumbers IdNum on Table_Name.Id = IdNum.Id
WHERE
DV = @DV
And then the following function:
CREATE FUNCTION Split(@CommaDelimitedFieldNames Varchar(8000), @Character VarChar(20)) RETURNS @Tbl_FieldNames TABLE (Id Integer IDENTITY (1, 1), FieldName VarChar(100)) AS BEGIN SET @CommaDelimitedFieldNames = @CommaDelimitedFieldNames + @Character DECLARE @Pos1 Int DECLARE @pos2 Int SET @Pos1 = 1 SET @Pos2 = 1 WHILE @Pos1 < Len(@CommaDelimitedFieldNames) BEGIN SET @Pos1 = CharIndex(@Character, @CommaDelimitedFieldNames, @Pos1) INSERT @Tbl_FieldNames SELECT Cast(Substring(@CommaDelimitedFieldNames, @Pos2, @Pos1 - @Pos2) AS VarChar(100)) SET @Pos2 = @Pos1 + 1 SET @Pos1 = @Pos1 + 1 END RETURN END
the way I call the procedure is
testingprocedure '1,2,3,4,5,6,7', 1
This works fine but my problem is that I have several thousand IDs I need to past to the procedure and this method will just not work. Does anyone knows a way around it? Thanks
I have the following stored procedure:
CREATE PROCEDURE testingprocedure
(
@IDs VarChar(8000),
@DV int
)
AS
Declare @IdNumbers Table(Id Integer)
Insert
Into @IdNumbers(Id)
Select FieldName As Id from dbo.Split(@new_lettersID, ',')
SELECT
ID,
DATANAME,
DV
FROM
table_name
Inner Join @IdNumbers IdNum on Table_Name.Id = IdNum.Id
WHERE
DV = @DV
And then the following function:
CREATE FUNCTION Split(@CommaDelimitedFieldNames Varchar(8000), @Character VarChar(20)) RETURNS @Tbl_FieldNames TABLE (Id Integer IDENTITY (1, 1), FieldName VarChar(100)) AS BEGIN SET @CommaDelimitedFieldNames = @CommaDelimitedFieldNames + @Character DECLARE @Pos1 Int DECLARE @pos2 Int SET @Pos1 = 1 SET @Pos2 = 1 WHILE @Pos1 < Len(@CommaDelimitedFieldNames) BEGIN SET @Pos1 = CharIndex(@Character, @CommaDelimitedFieldNames, @Pos1) INSERT @Tbl_FieldNames SELECT Cast(Substring(@CommaDelimitedFieldNames, @Pos2, @Pos1 - @Pos2) AS VarChar(100)) SET @Pos2 = @Pos1 + 1 SET @Pos1 = @Pos1 + 1 END RETURN END
the way I call the procedure is
testingprocedure '1,2,3,4,5,6,7', 1
This works fine but my problem is that I have several thousand IDs I need to past to the procedure and this method will just not work. Does anyone knows a way around it? Thanks