Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Select all fields and use distinct value

Author  Topic 

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2011-04-12 : 17:00:43
Is there a way to select all the fields from a table and only select records where BatchGuid is unique? Thank you.

create table	#TempTable1
(
BatchGuid varchar(50),
BatchName varchar(50),
ReportDate datetime,
JobNumber varchar(20),
ReportStatus varchar(50),
ReportOwner varchar(50),
ApprovalLevel varchar(50)default 'N/A'
)

dmilam
Posting Yak Master

185 Posts

Posted - 2011-04-12 : 17:13:44
[code]
SELECT DISTINCT BatchGuid, BatchName, ....
FROM #TempTable1
[/code]
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-04-12 : 20:29:09
[code]
select *
from (select BatchGuid from #TempTable1 group by BatchGuid having count(*) = 1) u
inner join #TempTable1 t on u.BatchGuid = t.BatchGuid
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -