﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server Newbies  / change a result into one record / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 22 May 2013 00:47:58 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: change a result into one record</title><link>http://www.sqlservercentral.com/Forums/Topic1424223-1292-1.aspx</link><description>Thank you, Jeff and Dwain, for following up.</description><pubDate>Wed, 27 Feb 2013 05:41:38 GMT</pubDate><dc:creator>Ed Wagner</dc:creator></item><item><title>RE: change a result into one record</title><link>http://www.sqlservercentral.com/Forums/Topic1424223-1292-1.aspx</link><description>[quote][b]dmarz96 (2/26/2013)[/b]is there a way to get only one record or am i doint this wrong.[/quote]I think this is the statement that caused me to think only one of the rows was required.</description><pubDate>Wed, 27 Feb 2013 05:39:06 GMT</pubDate><dc:creator>Ed Wagner</dc:creator></item><item><title>RE: change a result into one record</title><link>http://www.sqlservercentral.com/Forums/Topic1424223-1292-1.aspx</link><description>[quote][b]ChrisM@Work (2/27/2013)[/b][hr]Jeff, you and Dwain may have missed [url=http://www.sqlservercentral.com/Forums/FindPost1424153.aspx]the preceeding part of this case[/url].@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.[/quote]Indeed I did but it looks like you've got it covered.</description><pubDate>Wed, 27 Feb 2013 04:50:11 GMT</pubDate><dc:creator>dwain.c</dc:creator></item><item><title>RE: change a result into one record</title><link>http://www.sqlservercentral.com/Forums/Topic1424223-1292-1.aspx</link><description>[code="sql"], 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 xLEFT JOIN Property p 	ON x.RM_ID = p.sCodeOUTER 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 [/code]</description><pubDate>Wed, 27 Feb 2013 01:28:28 GMT</pubDate><dc:creator>ChrisM@Work</dc:creator></item><item><title>RE: change a result into one record</title><link>http://www.sqlservercentral.com/Forums/Topic1424223-1292-1.aspx</link><description>[quote][b]Jeff Moden (2/26/2013)[/b][hr][quote][b]dwain.c (2/26/2013)[/b][hr]I did have to make an assumption (the 0 in the second row of the set up data) as the OP only provided 4 data columns in that row but 5 in the first row.[/quote]Agreed.@dmarz96,Just to give you a leg up for your future posts, take a look at the article at the first link in my signature line below.  It'll really help you get a very high quality coded answer in a pretty short time.[/quote]Jeff, you and Dwain may have missed [url=http://www.sqlservercentral.com/Forums/FindPost1424153.aspx]the preceeding part of this case[/url].@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.</description><pubDate>Wed, 27 Feb 2013 01:14:14 GMT</pubDate><dc:creator>ChrisM@Work</dc:creator></item><item><title>RE: change a result into one record</title><link>http://www.sqlservercentral.com/Forums/Topic1424223-1292-1.aspx</link><description>[quote][b]dwain.c (2/26/2013)[/b][hr]I did have to make an assumption (the 0 in the second row of the set up data) as the OP only provided 4 data columns in that row but 5 in the first row.[/quote]Agreed.@dmarz96,Just to give you a leg up for your future posts, take a look at the article at the first link in my signature line below.  It'll really help you get a very high quality coded answer in a pretty short time.</description><pubDate>Tue, 26 Feb 2013 20:44:43 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: change a result into one record</title><link>http://www.sqlservercentral.com/Forums/Topic1424223-1292-1.aspx</link><description>[quote][b]Jeff Moden (2/26/2013)[/b][hr][quote][b]dwain.c (2/26/2013)[/b][hr]Like this?[/quote]Looks like it.  Heh... we make a hell of a tag team.  I'll flush out the requiremments, you write the code. :-)[/quote]Yeah, aren't we though?I did have to make an assumption (the 0 in the second row of the set up data) as the OP only provided 4 data columns in that row but 5 in the first row.</description><pubDate>Tue, 26 Feb 2013 20:36:11 GMT</pubDate><dc:creator>dwain.c</dc:creator></item><item><title>RE: change a result into one record</title><link>http://www.sqlservercentral.com/Forums/Topic1424223-1292-1.aspx</link><description>[quote][b]dwain.c (2/26/2013)[/b][hr]Like this?[/quote]Looks like it.  Heh... we make a hell of a tag team.  I'll flush out the requiremments, you write the code. :-)</description><pubDate>Tue, 26 Feb 2013 20:29:12 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: change a result into one record</title><link>http://www.sqlservercentral.com/Forums/Topic1424223-1292-1.aspx</link><description>Like this?[code="sql"]WITH PriorResults (HPROP, STYPE, SVALUE, NSFFee, SecDepIntRate) AS (    SELECT 240, 'DDEPOSITINTEREST', 0, NULL, 3000.0000    UNION ALL SELECT 240, 'NSFFee', 0, 50.0000, NULL)SELECT HPROP    ,NSFFee=SUM(NSFFee)    ,SecDepIntRate=SUM(SecDepIntRate)FROM PriorResultsGROUP BY HPROP[/code]</description><pubDate>Tue, 26 Feb 2013 18:45:46 GMT</pubDate><dc:creator>dwain.c</dc:creator></item><item><title>RE: change a result into one record</title><link>http://www.sqlservercentral.com/Forums/Topic1424223-1292-1.aspx</link><description>The ladder I want to combine the rows into one record.the codeSELECT 	p.HPROP, 	p.STYPE, 	p.SVALUE,	NSFFee = CASE WHEN p.STYPE = 'nsffee' THEN p.hvalue END,    SecDepIntRate = CASE WHEN p.STYPE = 'DDEPOSITINTEREST' THEN p.hvalue END FROM PROPOPTIONS PWHERE  p.hprop = '240' and p.STYPE IN ('nsffee','DDEPOSITINTEREST')the resultHPROP	STYPE	                           SVALUE	NSFFee	SecDepIntRate240	DDEPOSITINTEREST	0	NULL	3000.0000240	NSFFee		                           50.0000	NULLwhat I'm looking for is hprop       nsffee        SecDepIntRate240          50.0000     3000.0000</description><pubDate>Tue, 26 Feb 2013 13:41:24 GMT</pubDate><dc:creator>dmarz96</dc:creator></item><item><title>RE: change a result into one record</title><link>http://www.sqlservercentral.com/Forums/Topic1424223-1292-1.aspx</link><description>[quote][b]dmarz96 (2/26/2013)[/b][hr]That is not going to work for me.[/quote]So, what is it that you actually want?  which of the two row do you want returned or do you want to somehow combine the rows?  Be specific.</description><pubDate>Tue, 26 Feb 2013 13:35:52 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: change a result into one record</title><link>http://www.sqlservercentral.com/Forums/Topic1424223-1292-1.aspx</link><description>That is not going to work for me.</description><pubDate>Tue, 26 Feb 2013 13:25:41 GMT</pubDate><dc:creator>dmarz96</dc:creator></item><item><title>RE: change a result into one record</title><link>http://www.sqlservercentral.com/Forums/Topic1424223-1292-1.aspx</link><description>You could use SELECT TOP 1, but I don't know if that's what you really want.If you have more than one row meeting your search criteria, you should either want to return both or further refine your WHERE clause to return only the specific one you want.  If you do want only one of them (say the last one added) and use TOP, make sure you include an ORDER BY clause to make the results consistent.</description><pubDate>Tue, 26 Feb 2013 13:11:54 GMT</pubDate><dc:creator>Ed Wagner</dc:creator></item><item><title>change a result into one record</title><link>http://www.sqlservercentral.com/Forums/Topic1424223-1292-1.aspx</link><description>this is the code I used to retrieve a record set.SELECT 	p.HPROP, 	p.STYPE, 	p.SVALUE,	NSFFee = CASE WHEN p.STYPE = 'nsffee' THEN p.hvalue END,    SecDepIntRate = CASE WHEN p.STYPE = 'DDEPOSITINTEREST' THEN p.hvalue END FROM PROPOPTIONS PWHERE  p.hprop = '240' and p.STYPE IN ('nsffee','DDEPOSITINTEREST')my result is as followedHPROP	STYPE	                           SVALUE	NSFFee	SecDepIntRate240	DDEPOSITINTEREST	0	NULL	3000.0000240	NSFFee		                           50.0000	NULLis there a way to get only one record or am i doint this wrong.</description><pubDate>Tue, 26 Feb 2013 12:49:10 GMT</pubDate><dc:creator>dmarz96</dc:creator></item></channel></rss>