Re: Scalar Functions in Group By Clause returning invalid values
From: Hugo Kornelis (hugo_at_pe_NO_rFact.in_SPAM_fo)
Date: 01/04/05
- Next message: Bob Barrows [MVP]: "Re: REPLACE function doesn't work"
- Previous message: Louis Davidson: "Re: Puzzle: dateadd workdays only"
- In reply to: mikekimber1: "RE: Scalar Functions in Group By Clause returning invalid values"
- Next in thread: mikekimber1: "Re: Scalar Functions in Group By Clause returning invalid values"
- Reply: mikekimber1: "Re: Scalar Functions in Group By Clause returning invalid values"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 04 Jan 2005 22:14:45 +0100
On Tue, 4 Jan 2005 03:29:01 -0800, mikekimber1 wrote:
> *** SORRY CORRECT SQL STATEMENT!! ***
>
>SQL Statement :
>
>SELECT
>test.FLODS_UTL_LKUP_VALUE_FUNC('LGNCC_INTLOGHDR','CLIENTTYPE',t1.CLIENTTYPE),
>
>test.FLODS_UTL_LKUP_VALUE_FUNC('LGNCC_INTLOGHDR','INITCHANNEL',t1.INITCHANNEL),
> count(1) As Total
>FROM LGNCC_INTLOGHDR t1
>GROUP BY
>test.FLODS_UTL_LKUP_VALUE_FUNC('LGNCC_INTLOGHDR','CLIENTTYPE',t1.CLIENTTYPE),
>
>test.FLODS_UTL_LKUP_VALUE_FUNC('LGNCC_INTLOGHDR','INITCHANNEL',t1.INITCHANNEL)
>ORDER BY 1,2
Hi Mike,
Are you aware that the function will be executed twice for each row in
LGNCC_INTLOGHDR? I'm afraid that your query won't scale well...
If I read the code of your function correctly, I think you could change
the above query to the following, using joins instead of your user-defined
function:
SELECT COALESCE (ct.DISPLAY_NAME, 'Unspecified') AS ClientType,
COALESCE (ic.DISPLAY_NAME, 'Unspecified') AS InitChannel,
COUNT(*) AS Total
FROM LGNCC_INTLOGHDR AS t1
LEFT JOIN FLODS_UTL_LOOKUP_CODE AS ct
ON ct.LOOKUP_GROUP = 'LGNCC_INTLOGHDR'
AND ct.SUB_GROUP = 'CLIENTTYPE'
AND ct.LOOKUP_VALUE = t1.CLIENTTYPE
LEFT JOIN FLODS_UTL_LOOKUP_CODE AS ic
ON ic.LOOKUP_GROUP = 'LGNCC_INTLOGHDR'
AND ic.SUB_GROUP = 'INITCHANNEL'
AND ic.LOOKUP_VALUE = t1.INITCHANNEL
GROUP BY COALESCE (ct.DISPLAY_NAME, 'Unspecified'),
COALESCE (ic.DISPLAY_NAME, 'Unspecified')
ORDER BY 1, 2
(untested)
Best, Hugo
-- (Remove _NO_ and _SPAM_ to get my e-mail address)
- Next message: Bob Barrows [MVP]: "Re: REPLACE function doesn't work"
- Previous message: Louis Davidson: "Re: Puzzle: dateadd workdays only"
- In reply to: mikekimber1: "RE: Scalar Functions in Group By Clause returning invalid values"
- Next in thread: mikekimber1: "Re: Scalar Functions in Group By Clause returning invalid values"
- Reply: mikekimber1: "Re: Scalar Functions in Group By Clause returning invalid values"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|