I want to retrieve the columns from the table., depending on the conditions.,
what I can use.
For example, I’ ve fields namely, add order comments, cancel order comments, postpone order comments, action(add, cancel, postpone) and amount received(Y/N)
Now I’ve to fetch columns add order comments, cancel order comments, postpone order comments depending on action and amount received.,
if(action='add' and amount received='Y')
then
i've to fetch add order comments column
elseif(action='postpone' and amount received='Y')
then
i've to fetch postpone order comments column
else (action='cancel')
then i've to fetch cancel order comments
how to get this done in sql or plsql., I want this conditions in select statement
Note that by “sql or plsql” I’m assuming that “sql” refers to T-SQL as used by MS SQL Server. If not, please use the appropriate equivalent in your language.
You need to use a CASE (T-SQL) statement (PL-SQL equivalent)
For example, in T-SQL:
Note also that in the rules you’ve given, if the
amountRcdfield is notY, then you will get “Unrecognised action” as the comment. I think you may need to clarify your rules to prevent this.