lundi 29 novembre 2021

Fail Result for if-else condition in sql

if @RevisionId in(2,3) Begin If @ObjectId like '%1%' OR @ObjectId like '%2%' and @RevisionId =2 Begin If @ObjectId = '1' Begin
print 'ObjectId1 rev2' End
else If @ObjectId = '2' Begin

                print 'ObjectId2 rev 2'
                End 
        End 
        else If @ObjectId like '%1%' OR @ObjectId like '%2%' and @RevisionId =3
            Begin
            If @ObjectId = '1'
                Begin   
                print 'ObjectId1 rev3'
                End  
            End 
            else  If @ObjectId = '2'
            Begin
                print 'ObjectId2 rev3'
            End   
    End 
    -----
    Expected Result :
For RevisionId 2 and ObjectId 1 -> ObjectId1 rev2
For RevisionId 2 and ObjectId 2 -> ObjectId2 rev2
For RevisionId 3 and ObjectId 1 -> ObjectId1 rev3
For RevisionId 3 and ObjectId 2 -> ObjectId2 rev3
    ------

Aucun commentaire:

Enregistrer un commentaire