mercredi 5 juin 2019

Not entering SQL if statement

I have a problem with entering an if statement in SQL Server.

I tried wrapping the if inner statements in BEGIN END blocks but no luck.

```if (CHARINDEX(',', @Configs, 0) = 0)
    print 'Single config detected'
    begin
        if (@configAlreadyExists = 0)
        begin
            print 'Cofnig ' + @Configs + ' isn''t in the Health Check config display list, checking if it exists in table...'
            if not exists (select 1 from table where ConfigKey = @Configs)
                begin 
                    print 'Cofnig ' + @Configs + ' doesn''t exist in table, add the config first.'
                end
            else
                begin
                    print 'Cofnig ' + @Config + ' exists in table, adding config for Health Check display.'
                end
        end
    end```

If I enter any string I would expect to eventually see the exists or doesn't exist in table printout, but I don't.

The only printout I see is 'Single config detected'.

Any thoughts?

Thanks.

Aucun commentaire:

Enregistrer un commentaire