I’m trying to solve this issue with only one select. It can be easily solved with 2, but I want only one:
Imagine this simple table:
create table CheckTest(
name varchar(50)
)
I want a query that fail (it will be inside an if statement) if there isn’t any rows on the table or there is a row with name=’test’
So, these are the possible scenarios:
--scenario 1 - no rows: should fail
truncate table CheckTest
--scenario2 - rows with value different than "test": should succeed
insert into CheckTest values ('OK')
insert into CheckTest values ('OK')
--scenario3 - 1 row with value "test" or 1 row with value "test" among other rows with value OK
insert into CheckTest values ('test')
insert into CheckTest values ('OK')
insert into CheckTest values ('OK')
I’m planning on using the check like this:
if (<check>)
print 'fail'
else
print 'continue'
It is possible like this: