on 2011 Feb 24 3:49 PM
Wondering if anyone can shed some light on the possibilies of having a list() in a case statement. ex:
select (case
when [field] = [x] then list([y], [z])
else [a]
end)
from [table]
couldn't find any documentation and the list() function seems a bit limited from the documents info.
Appreciate your help. I'm using sql anywhere 11.
Request clarification before answering.
LIST does work in a CASE expression. The following is a (not very useful) sample:
select case
when creator <> 3
then 'System procs: ' || list(proc_name, ', ' order by proc_name)
else 'My procs: ' || list(proc_name, ', ' order by proc_name)
end case as MyProcList
from sysprocedure group by creator
Note, however, that LIST is an aggregate function, i.e. the [field] you refer to in the CASE WHEN expression must be part of the GROUP BY clause.
That's the reason I used "GROUP BY creator".
As to your notation of (list[y], [z]): Note that LIST is not a string concatenation, instead it lists all particular values per group. A simple string concatenation can be done with operator || (as in the sample) or the STRING function.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
9 | |
8 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.