I want to get RollNo
if it is present when certain conditions meet otherwise it should return -1 . But in my case it is returning RollNo
when its present, otherwise it returns nothing .
SQL is under:-
SELECT iif(isnull(RollNo),-1,RollNo) from students where SName = "sf" and FName= "da" and
DOB=#7/16/2020# and ClassID = 0
Hmm. . . If you always want to return exactly one row, then I would suggest aggregation:
SELECT NZ(MAX(RollNo), -1)
FROM students
WHERE SName = "sf" and FName= "da" and DOB=#7/16/2020# and ClassID = 0;
If nothing matches the WHERE
clause, then MAX(RollNo)
returns NULL
-- which is converted to a -1
by NZ()
.
This returns exactly one row with field RollNo
.
SELECT iif(isnull(max(RollNo)),-1,max(RollNo)) from students where SName = "sf" and
FName= "da" and DOB=#7/16/2020# and ClassID = 0
if the conditions in where clause meet it return RollNo
otherwise return -1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.