SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Delete duplicate row based on one column, but need to retain rest of the values in tmp file


Delete duplicate row based on one column, but need to retain rest of the values in tmp file

Author
Message
Gillian_Pappas2002
Gillian_Pappas2002
SSC-Enthusiastic
SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)

Group: General Forum Members
Points: 166 Visits: 122
I must not be having good luck today. I've added it as a docx, and a .txt
Attachments
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25994 Visits: 17528
Gillian_Pappas2002 (12/18/2013)
My posts look fine in preview then get messed up when I post it. Sorry. I have included an attachment.

Thanks for all of your help.


Displaying tabular information is not something html is good at. That is why there are html tables. UGH!!! It is generally best to just create a temp table for your results. It only takes a few more seconds.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Igor Micev
Igor Micev
SSCertifiable
SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)

Group: General Forum Members
Points: 5886 Visits: 5080
Gillian_Pappas2002 (12/18/2013)
Thank you so much. That worked really well, but for some reason, there remain a few randon duplicate co_nums rows showing up. But I truly appreciate your help. Thanks. G


Hi,

Pay attention on this fragment of the above posted code:
OVER(PARTITION by inv_num ORDER BY name)

You've decided to remove duplicates based on inv_num and here you're telling us about some co_nums.
You can also specify more columns after PARTITION BY... as well as in after ORDER BY..
I think you'll manage to settle up your results.

Regards,
IgorMi

Igor Micev,
SQL Server developer at Seavus
My blog: www.igormicev.com
Gillian_Pappas2002
Gillian_Pappas2002
SSC-Enthusiastic
SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)

Group: General Forum Members
Points: 166 Visits: 122
Thank you.
Gillian_Pappas2002
Gillian_Pappas2002
SSC-Enthusiastic
SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)

Group: General Forum Members
Points: 166 Visits: 122
Yes, I was try to remove duplicates based on Co_num. Thank you.
Gillian_Pappas2002
Gillian_Pappas2002
SSC-Enthusiastic
SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)

Group: General Forum Members
Points: 166 Visits: 122
Thank you so very much. For some reason when I moved everything from the #temp table over to a @temp table and applied your logic....

;WITH cte as
(
SELECT *,
ROW_NUMBER() OVER(PARTITION by co_num ORDER BY name) AS dupCnt
FROM @tmp_FullfillOrder2
)
--Now Delete Duplicate Records
DELETE FROM cte
WHERE dupCnt > 1

select * from @tmp_FullfillOrder2


Dupicates were removed, but all of the rest of my calculations, etc., were intact. I can't thank you enough for all of your help and all of the great people who help us here at SqlServerCentral. You all are SUPER. Thank you again.

Gillian
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search