Image

Imagealarthame wrote in Imagesqlserver

hi all

Hello,

This is my first time posting here. I'm pretty new at SQL but I think that I am learning. :) Anyway, I have a sort of issue that I am hoping someone can clarify for me.

At my job, I am trying to fix up a query someone else made, forcing it to have all unique "PSourceIDs." Obviously, I can get 2 of the same number if I select distincts and then have two entries with different values anywhere in the record. So, here is what I was trying to do, eventhough it fails when I run it:


drop table #NewTest
select distinct psourceid into #NewTest
from #Test T
select * from #NewTest

insert into #NewTest (Priority, COSupplierCode, Aging, AgingToNow)
select Priority, COSupplierCode, Aging, AgingToNow
from #Test T
where (T.psourceid = #NewTest.psourceid)
select * from #NewTest


Firstly, can I do this with temp tables, and secondly, if so, then where did my logic fail?