あなたの答えの前に、私はマッチカウントを返し、count = 10の場所を取得する以下の関数を使用しています
Create FUNCTION [dbo].[MatchRows]
(
@id int,
@No1 int,
@No2 int,
@No3 int,
@No4 int,
@No5 int,
@No6 int,
@No7 int,
@No8 int,
@No9 int,
@No10 int
)
RETURNS bit
AS
BEGIN
Declare @ReturnVal bit = 0;
Declare @Allvalue varchar(max);
Declare @CntMatch int;
SELECT @Allvalue = ',' + Convert(varchar(3),No1)+ ',' +
Convert(varchar(3),No2)+ ',' +
Convert(varchar(3),No3)+ ',' +
Convert(varchar(3),No4)+ ',' +
Convert(varchar(3),No5)+ ',' +
Convert(varchar(3),No6)+ ',' +
Convert(varchar(3),No7)+ ',' +
Convert(varchar(3),No8)+ ',' +
Convert(varchar(3),No9)+ ',' +
Convert(varchar(3),No10)+ ',' +
Convert(varchar(3),No11)+ ',' +
Convert(varchar(3),No12)+ ',' +
Convert(varchar(3),No13)+ ',' +
Convert(varchar(3),No14)+ ',' +
Convert(varchar(3),No15)+ ',' +
Convert(varchar(3),No16)+ ',' +
Convert(varchar(3),No17)+ ',' +
Convert(varchar(3),No18)+ ',' +
Convert(varchar(3),No19)+ ',' +
Convert(varchar(3),No20)+ ','
FROM DrawFinalResult
WHERE ID = @ID;
SET @CntMatch = 0;
Select @CntMatch += (CASE WHEN CHARINDEX(','+ Convert (varchar(3),@No1) +',',@Allvalue) > 0 THEN 1 Else 0 END);
Select @CntMatch += (CASE WHEN CHARINDEX(','+ Convert (varchar(3),@No2) +',',@Allvalue) > 0 THEN 1 Else 0 END);
Select @CntMatch += (CASE WHEN CHARINDEX(','+ Convert (varchar(3),@No3) +',',@Allvalue) > 0 THEN 1 Else 0 END);
Select @CntMatch += (CASE WHEN CHARINDEX(','+ Convert (varchar(3),@No4) +',',@Allvalue) > 0 THEN 1 Else 0 END);
Select @CntMatch += (CASE WHEN CHARINDEX(','+ Convert (varchar(3),@No5) +',',@Allvalue) > 0 THEN 1 Else 0 END);
Select @CntMatch += (CASE WHEN CHARINDEX(','+ Convert (varchar(3),@No6) +',',@Allvalue) > 0 THEN 1 Else 0 END);
Select @CntMatch += (CASE WHEN CHARINDEX(','+ Convert (varchar(3),@No7) +',',@Allvalue) > 0 THEN 1 Else 0 END);
Select @CntMatch += (CASE WHEN CHARINDEX(','+ Convert (varchar(3),@No8) +',',@Allvalue) > 0 THEN 1 Else 0 END);
Select @CntMatch += (CASE WHEN CHARINDEX(','+ Convert (varchar(3),@No9) +',',@Allvalue) > 0 THEN 1 Else 0 END);
Select @CntMatch += (CASE WHEN CHARINDEX(','+ Convert (varchar(3),@No10) +',',@Allvalue) > 0 THEN 1 Else 0 END);
Set @ReturnVal = (CASE WHEN @CntMatch = 10 THEN 1 ELSE 0 END);
RETURN @ReturnVal
END