ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Remove duplicate records within select query in SQL Server<p>HI <a class="username" rel="PRA">PRA</a>,</p> <p>Refer below modified query.</p> <p><strong><span style="text-decoration: underline;">SQL</span></strong></p> <pre class="brush: sql">DECLARE @MANUALSICK AS TABLE (Id INT, NAMEBOL VARCHAR(150), price INT) INSERT INTO @MANUALSICK VALUES (9,&#39;Тахлили умумии пешоб&#39;,5) INSERT INTO @MANUALSICK VALUES (107,&#39;Муайян намудани гурухи хун ва резус омил&#39;,14) DECLARE @SPR_VRCH AS TABLE (KOD_VR INT, NAIM_VR VARCHAR(70)) INSERT INTO @SPR_VRCH VALUES(7,&#39;Холмуродова Гулрухсор&#39;) DECLARE @kassa AS TABLE (Id INT,iddoc int ,name_shah VARCHAR(30),rasid_roh VARCHAR(10), talon_roh INT) INSERT INTO @kassa VALUES(1,7,&#39;Мадралиева Ш&#39;,&#39;9,107&#39;,7) DECLARE @IdPer INT SET @IdPer = 7 SELECT DISTINCT PersonId, STUFF((SELECT &#39;,&#39; + NAMEBOL FROM( SELECT k.talon_roh PersonId,LTRIM(RTRIM(m.NAMEBOL))NAMEBOL FROM @MANUALSICK m, @kassa k WHERE m.Id IN (SELECT CAST(item AS INTEGER) FROM dbo.SplitString(k.rasid_roh, &#39;,&#39;)) AND k.IdDoc = @IdPer ) as childTable WHERE mainTable.PersonId = childTable.PersonId FOR XML PATH(&#39;&#39;)), 1, 1, &#39; &#39;) AS Name, naim_vr, name_shah, (SELECT SUM(m.Price) FROM ( SELECT CAST(Item AS INTEGER) Item FROM dbo.SplitString((SELECT TOP 1 rasid_roh FROM @kassa WHERE IdDoc = @IdPer ORDER BY talon_roh DESC), &#39;,&#39;) )t INNER JOIN @MANUALSICK m ON m.Id = t.Item) Price FROM( SELECT k.talon_roh PersonId,v.NAIM_VR,k.name_shah,m.PRICE FROM @kassa k JOIN @SPR_VRCH v ON k.IdDoc = v.KOD_VR, @MANUALSICK m WHERE k.talon_roh = (SELECT MAX(talon_roh) FROM @kassa WHERE IdDoc = @IdPer) and k.IdDoc = @IdPer )AS mainTable GROUP BY mainTable.NAIM_VR,mainTable.name_shah,mainTable.PersonId,mainTable.PRICE</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/615249/Remove-duplicate-records-within-select-query-in-SQL-Server/https://www.aspforums.net:443/Threads/615249/Remove-duplicate-records-within-select-query-in-SQL-Server/Mon, 15 Oct 2018 04:51:37 GMT