Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

removing duplcates in a temp table

Status
Not open for further replies.

Newbi1

Programmer
Apr 4, 2005
64
0
0
US
I have several rows duplicated in my temp table that contain text and objects.

As I am creating the procedure to create the table, is there any way of filtering out to insert only 1 record per ID?

I have tried grouping and selecting distinct, however because of the text fields, it will not allow me to.

An help would be appreciated
 
Does it matter which row you insert? For example if you have 3 rows for the same ID, does it matter which one you insert into your table?
 
Try using a loop"
Code:
declare @IDCnt int
declare @ID int

Select [ID]
Into #IDs
From <table>
Group By ID

Set @IDcnt = Select Count(*) From #IDs
Set @ID = Select Min([ID}) From #IDS

While @IDcnt <> 0
BEGIN
   Insert Into <temp table>
   Select TOP 1 <cols> from <table> where [ID] = @ID

   Delete From #IDs where [ID] = @ID
   Set @IDcnt = Select Count(*) From #IDs
END
 
Not sure yet... I modified the query to fid the DB and it has been running for almost an hour.

I am glad it only needs to be scheduled once a day.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top