Re: Strange problem with max()?



On Mar 14, 4:25 am, sergei.shei...@xxxxxx wrote:
Hello,

I've been at this problem all morning. Below you can see select sql
with included select in where statement. I have to use the max
function on the included select. The included select statement takes
only 10 seconds to execute and returns just under 4000 rows.

When I execute the entire statement, it GETS STUCK! If I remove max
and group by from the included select, everything executes well, but I
get wrong results, of course.

select * from TB_TRADE as TRD
where

CL_TRADE_ID in (select max(t.CL_TRADE_ID)
from TB_TRADE t inner join TB_TRADE_SET s
on t.CL_TRADE_SET_ID=s.CL_TRADE_SET_ID
and t.CL_VERSION = s.CL_VERSION
where s.CL_TRADE_DATE = convert(int, convert(char(8), dateadd(day,
-1, getdate()), 112))

and s.CL_STATUS in ('I','A')

and t.CL_BUY_SELL = 'S'
and t.CL_TRADE_BASIS = 'PR'
and t.CL_TRADE_CURRENCY = 'RUB'
group by s.CL_TRADE_SET_ID
)

Heeelp!

It's a Sybase database.

Sergei.

Try using "cl_trade_id = (SELECT MAX(Tcl_trade_id) ..AND TRD.?? = ??"
or whatever you need to do to make it a scalar correlated subquery.
Without DDL, it is hard to say more. Also you might want to look at
the research on upper and lower case formatting -- you are using one
of the worst conventions. I had to test this when I was with the US
Army and we were trying to make ADA work.

.



Relevant Pages

  • Re: Dynamic VB Code Behind
    ... 'Dynamic Master/Detail Controls', but as I started abstracting the ... In this case when the user selects which report they want to run from a ddl ... My code will read from sql that it needs to create a ddl ... 'save' the SelectedIndexChanged event code in sql and send it to an Execute ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Adding a field
    ... maintain, slower to develop, and slower to execute, for no benefit. ... there is no way to set the default behavior for DDL queries. ... I don't believe that works under DAO, so it probably won't work if you ... Is there anyway to get them to default to true using SQL? ...
    (microsoft.public.access.queries)
  • Re: Opinions on approach, please...
    ... Create a data layer program per table, ... number of bind variable tokens in your dynamic SQL. ... then simply EXECUTE that without passing it any parameters? ... Hard code WHERE clauses. ...
    (comp.lang.cobol)
  • Re: SQL Injection- Bypassing magic_quotes
    ... Because i was trying to execute: ... Don't terminate the query and you most ... Or try something like bobcat or one of the other SQL injection tools out ... Chief Information Security Officer ...
    (Pen-Test)
  • Re: Opinions on approach, please...
    ... Create a data layer program per table, ... number of bind variable tokens in your dynamic SQL. ... then simply EXECUTE that without passing it any parameters? ... explicitly code dummy words as bind variable placekeepers, put the host variables on the ...
    (comp.lang.cobol)