Quantcast
Channel: OutSystems Community
Viewing all articles
Browse latest Browse all 1476385

[Forums] Using If's and selects

$
0
0

Kilian Hekhuis wrote:

Hi Miguel,

Conditionals in SQL are handled by the CASE statement. However, in your case, do you need to handle that in the query? Why not have an assignment after the query that assigns the values?

Also, having subqueries inside a SELECT might not be the best way to go about this. Do you really need them to be seperate columns? If not, you could do e.g. just

SELECT {StatusCore2}.[Label], COUNT(1)
FROM {DocumentCore2}
INNER JOIN {StatusCore2} ON {StatusCore2}.[Id] = {DocumentCore2}.[Status]
GROUP BY {StatusCore2}.[Label]

and then loop over the result and post-proces that. Or, if you do not even need the actual number of documents with the statusses, just a

SELECT DISTINCT {StatusCore2}.[Label]
FROM {DocumentCore2}
INNER JOIN {StatusCore2} ON {StatusCore2}.[Id] = {DocumentCore2}.[Status]

Thanks for the reply Kilian but that is what I have now.

I have 1 query that gets all documents. Then, for each document, I check the status is 'Completed' or 'Submited' and do the assignment depending on that. 

But I want to know if is possible to reduce this process, having only 1 query and no 'for each' cycle.



Viewing all articles
Browse latest Browse all 1476385