2004-10-01

Geeked out.

Slow day at the orifice.

I wrote this, though:

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

ALTER procedure rp_telefund_output
@list_no int
as

SELECT

t.customer_no, t.cust_type, t.prefix, t.fname, t.mname, t.lname, t.suffix, t.name_status,
t.prefix2, t.fname2, t.mname2, t.lname2, t.suffix2, t.sex2,
t.name2_status, t.primary_address_no, ad.address_type, ad.street1,
ad.street2, ad.city, ad.state, ad.postal_code, ad.primary_ind, t.inactive,
s.esal1_desc, s.esal2_desc, s.lsal_desc, s.business_title, p1.phone1,
p2.phone2, a.lastdate, c.cont_type, c.campaign_no AS lastcamp,
c.appeal_no AS lastappeal, c.cont_amt AS lastgift, c.media_type AS
lastmedia, c.source_no AS lastsource, c.fund_no AS lastfund
FROM

dbo.T_CONTRIBUTION c INNER JOIN
(SELECT MAX(cont_dt) AS
lastdate,
MIN(cont_dt) AS firstdate, customer_no
FROM
t_contribution

WHERE fund_no IN (8, 20, 22, 18, 10, 6)
GROUP
BY customer_no) a
ON c.customer_no = a.customer_no
AND
c.cont_dt = a.lastdate RIGHT OUTER
JOIN
dbo.T_CUSTOMER t INNER JOIN
dbo.T_ADDRESS
ad ON t.customer_no = ad.customer_no AND
t.primary_address_no = ad.address_no INNER JOIN
(SELECT
customer_no, esal1_desc, esal2_desc, lsal_desc, business_title
FROM tx_cust_sal
WHERE default_ind = 'Y') s ON t.customer_no = s.customer_no ON
a.customer_no = t.customer_no LEFT OUTER JOIN
(SELECT MAX(phone) AS phone1, customer_no
FROM t_phone
WHERE type = 1
GROUP BY customer_no) p1 ON t.customer_no = p1.customer_no LEFT OUTER JOIN
(SELECT MAX(phone) AS phone2, customer_no
FROM t_phone
WHERE type = 2
GROUP BY customer_no) p2
ON
t.customer_no = p2.customer_no
join t_list_contents l
on t.customer_no=l.customer_no
where l.list_no=@list_no


GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON

GO

Hott.

SQL is the poetry of the database world.

I'm gonna have it tattooed on my ass.

lisamcc at 1:02 p.m.



1 comments so far
Gimpy Old Lady
2004-10-02 19:59:51
Huh?
-------------------------------

previous | next