Re: Stuck on SQL Query where a calculated value is used for a join.

From: scottrarndt(at)aol(dot)com (ScottRArndt)
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Stuck on SQL Query where a calculated value is used for a join.
Date: 2002-12-27 13:57:56
Message-ID: 20021227085756.15080.00000741@mb-fe.aol.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Never mind ... a good night's sleep with my subconscious working on the
problem yielded:

SELECT
reg_type.reg_type_desc "Registration Type",
CASE result.result_defn
WHEN NULL THEN CONVERT(VARCHAR,reg_stats.result_code)
ELSE result.result_defn
END 'Result',
reg_stats.create_date "Create Date",
forms.logical_form_number,
-- FORM 1
CASE
WHEN
(CHARINDEX('',SUBSTRING(reg_trace.reg_trace1,CHARINDEX('992',reg_trace.
reg_trace1) + 5, 255)) - 1) < 0
THEN SUBSTRING(reg_trace.reg_trace1,CHARINDEX('992',reg_trace.reg_trace1)
+ 5,255)
ELSE
SUBSTRING(reg_trace.reg_trace1,CHARINDEX('992',reg_trace.reg_trace1)
+
5,CHARINDEX('',SUBSTRING(reg_trace.reg_trace1,CHARINDEX('992',reg_trace
.reg_trace1) + 5, 255)) - 1)
END 'Form 1',
-- END FORM 1
CASE CHARINDEX('992',reg_trace.reg_trace1)
WHEN 0 THEN 'No Forms Trace'
ELSE
SUBSTRING(reg_trace.reg_trace1,CHARINDEX('992',reg_trace.reg_trace1) +
5, 255)
END 'Forms Trace',
reg_trace.reg_trace1
from reg_stats, reg_trace, reg_type, result, forms
where
reg_stats.reg_type_code = reg_type.reg_type_code
and reg_stats.reg_stats_logical_key = reg_trace.reg_stats_logical_key
and reg_stats.result_code *= result.result_code
and reg_trace.reg_stats_logical_key in
(select reg_trace.reg_stats_logical_key
from reg_stats, reg_trace
WHERE reg_stats.reg_stats_logical_key = reg_trace.reg_stats_logical_key
and reg_stats.create_date >= "12/18/02 09:57:00"
and reg_stats.create_date <= "12/18/02 10:15:00"
and reg_trace.reg_trace1 like '%992%')
and forms.form_number =
CASE
WHEN
(CHARINDEX('',SUBSTRING(reg_trace.reg_trace1,CHARINDEX('992',reg_trace.
reg_trace1) + 5, 255)) - 1) < 0
THEN
convert(smallint,SUBSTRING(reg_trace.reg_trace1,CHARINDEX('992',reg_trac
e.reg_trace1) + 5,255))
ELSE
convert(smallint,SUBSTRING(reg_trace.reg_trace1,CHARINDEX('
992',reg_trace.reg_trace1) +
5,CHARINDEX('',SUBSTRING(reg_trace.reg_trace1,CHARINDEX('992',reg_trace
.reg_trace1) + 5, 255)) - 1))
END

Browse pgsql-sql by date

  From Date Subject
Next Message Gary Stainburn 2002-12-28 15:13:31 COPY fails but INSERT works
Previous Message Evgen Potemkin 2002-12-27 13:32:54 Reference integrity question