I ran into a problem while executing queries using the CASE statement. Based on my condition (e.g. length), I want to execute a different SQL statement.
A problematic query example is as follows:
select case
when char_length('19480821') = 8
then select count(1) from Patient
when char_length('19480821')=10
then select count(1) from Doctor
end
An exception:
[Error] Script line: 1-5 --------------------------
Invalid syntax next to the keyword "select".
Msg: 156, Level: 15, State: 2
Server: sunsrv4z7, Line: 2
I can not fix the syntax. I get a string for char_length as input from the user. How can I run queries based on certain conditions? Is CASE the right choice? Or should I use any other thing.