Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

change a result into one record Expand / Collapse
Author
Message
Posted Wednesday, February 27, 2013 1:28 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:38 AM
Points: 7,208, Visits: 13,669
, x.FAC_ACTIVITY [FAC_ACTIVITY]
, x.NUMMAINTEMP [NUMMAINTEMP]
, LH.dtLeaseFrom [LHdtLeaseFrom]
, LH.dtLeaseTo [LHdtleaseto]
, crp.destimated [crpdestimated]
--, pps.HValue [ppsNSFFEE]

,pps.NSFFee
,pps.MTMFee
,pps.SecDepIntRate

, m.stext [memoStext]

FROM vw_DK_RMMISCDATA x
LEFT JOIN Property p
ON x.RM_ID = p.sCode
OUTER APPLY ( -- flatten relevant rows from PropOptions
SELECT
HPROP = MAX(po.HPROP),
STYPE = MAX(po.STYPE),
SVALUE = MAX(po.SVALUE),
NSFFee = MAX(CASE WHEN po.STYPE = 'nsffee' THEN po.hvalue END),
MTMFee = MAX(CASE WHEN po.STYPE = 'MTMFee' THEN po.hvalue END),
SecDepIntRate = MAX(CASE WHEN po.STYPE = 'DDEPOSITINTEREST' THEN po.hvalue END)
FROM PROPOPTIONS po
WHERE po.HPROP = p.hmy -- outer reference
AND po.STYPE IN ('nsffee', 'MTMFee', 'DDEPOSITINTEREST') -- filter
) pps



“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Post #1424390
Posted Wednesday, February 27, 2013 4:50 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 6:20 AM
Points: 3,627, Visits: 5,269
ChrisM@Work (2/27/2013)
Jeff, you and Dwain may have missed the preceeding part of this case.

@dmarz96, it's much easier to see what you are trying to do, now that I've seen both threads. Often, breaking a case up into different threads like this causes confusion and fragmented replies as no single thread has all of the information required to put together a solution.


Indeed I did but it looks like you've got it covered.



My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!

My thought question: Have you ever been told that your query runs too fast?

My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.


Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
Post #1424466
Posted Wednesday, February 27, 2013 5:39 AM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 12:58 PM
Points: 4,189, Visits: 3,227
dmarz96 (2/26/2013)is there a way to get only one record or am i doint this wrong.


I think this is the statement that caused me to think only one of the rows was required.



Tally Tables - Performance Personified
String Splitting with True Performance
Best practices on how to ask questions
Post #1424475
Posted Wednesday, February 27, 2013 5:41 AM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 12:58 PM
Points: 4,189, Visits: 3,227
Thank you, Jeff and Dwain, for following up.


Tally Tables - Performance Personified
String Splitting with True Performance
Best practices on how to ask questions
Post #1424477
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse