I have C# and SQL code that work together. Issue was I need to add more than 4 modifier in my list but it was not possible, so I change the c# code and related to that I need to change my SQL code. I do not know how may I put for loop in SQL. Help me please.
I have a table that I need to add "n" modifier on it.
Here is the c# code that I changed:
int n = updatedStudy.Modifiers.Count;
for (int i = 1; i < n; i++)
{
string @pu_examCodeModifier = "@pu_examCodeModifier" + i;
sqlParm.Add(@pu_examCodeModifier, updatedStudy.Modifiers[i - 1].Key, SQLEnumerations.SQLDataTypes.UNIQUEIDENTIFIER, 0);
}
and here is SQL code that I need to change :
CREATE PROCEDURE [v0000].[apUpdateOrder] (
@pu_fillerOrderKey UNIQUEIDENTIFIER,
@pu_examCodeKey UNIQUEIDENTIFIER,
@pu_examCodeModifier1 UNIQUEIDENTIFIER = NULL ,
@pu_examCodeModifier2 UNIQUEIDENTIFIER = NULL,
@pu_examCodeModifier3 UNIQUEIDENTIFIER = NULL,
@pu_examCodeModifier4 UNIQUEIDENTIFIER = NULL,
@ps_fillerOrderStatusCd VARCHAR(1),
@ps_priorityCd VARCHAR(10),
@pb_exam_stat_flag BIT)
AS
BEGIN
--exam code modifiers
IF (@pb_updateStudyModifiers IS NOT NULL)
BEGIN
DELETE FROM dbo.mapProcedureStepExamCodeModifier
WHERE procedureStepKey = @lu_procedureStepKey
IF (@pu_examCodeModifier1 IS NOT NULL)
INSERT INTO dbo.mapProcedureStepExamCodeModifier (procedureStepKey, examCodeModifierKey)
VALUES (@lu_procedureStepKey, @pu_examCodeModifier1)
IF (@pu_examCodeModifier2 IS NOT NULL)
INSERT INTO dbo.mapProcedureStepExamCodeModifier (procedureStepKey, examCodeModifierKey)
VALUES (@lu_procedureStepKey, @pu_examCodeModifier2)
IF (@pu_examCodeModifier3 IS NOT NULL)
INSERT INTO dbo.mapProcedureStepExamCodeModifier (procedureStepKey, examCodeModifierKey)
VALUES (@lu_procedureStepKey, @pu_examCodeModifier3)
IF (@pu_examCodeModifier4 IS NOT NULL)
INSERT INTO dbo.mapProcedureStepExamCodeModifier (procedureStepKey, examCodeModifierKey)
VALUES (@lu_procedureStepKey, @pu_examCodeModifier4)
END