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)
 How can I select?

Author  Topic 

mikezang
Starting Member

2 Posts

Posted - 2010-07-07 : 23:17:46
There are several records in the same OrderNo, if GoodsCode of one of them is '7777000100010', I have to select it, if no such record, select any one of else.
my SQL as below, now I got result but they are not distinct with same OrderNo, I want to get distinct result, what can I modify my SQL?
SELECT DISTINCT       
convert(varchar,convert(datetime,[RegisterData]),111)as [RegisterDate],[ExportNo],[OrderNo],
[ArriveDate] = case [GoodsCode] when '7777000100010' THEN 'No' ELSE [ArriveDate] END, [Name],
[GoodsCode] = case [GoodsCode] when '7777000100010' THEN 'TodayArrive' ELSE 'ArriveOnDate' END
FROM [myTable](nolock) order by RegisterData desc

mikezang
Starting Member

2 Posts

Posted - 2010-07-07 : 23:36:36
I got it with group by.
Go to Top of Page
   

- Advertisement -