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)
 Simple Group by query?

Author  Topic 

Nroblex
Starting Member

17 Posts

Posted - 2010-03-18 : 09:59:23
Hi Gurus.

Perhaps you can help me out with this?

I have a simple table like this:

[CreatedTimeStamp](dateTime) [StatusValue] varchar(20)
2010-03-19 19:20:23.949 'Incomming'
2010-03-19 19:20:24.843 'Sending'
2010-03-19 19:20:25.521 'Recieved'
2010-03-19 19:20:25.526 'Recieved'

As you can se the third and fourth line are identical in the StatusValue column

I Want to use an sql-query that returns different records on both columns. How would you construct that query?

The result must be like this:
[CreatedTimeStamp](dateTime) [StatusValue] varchar(20)
2010-03-19 19:20:23.949 'Incomming'
2010-03-19 19:20:24.843 'Sending'
2010-03-19 19:20:25.521 'Recieved'


Many Thanks in advance

//Nroblex

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-03-18 : 10:28:09
Try it and let me know if it helps you.



Declare @Temp Table
(CreatedTimeStamp datetime,
StatusValue Varchar(20)
)

Insert into @Temp
Select '2010-03-19 19:20:23.949', 'Incomming'
union
Select '2010-03-19 19:20:24.843', 'Sending'
Union
Select '2010-03-19 19:20:25.521', 'Recieved'
Union
Select '2010-03-19 19:20:25.526', 'Recieved'


select * from @Temp

Select min(CreatedTimeStamp), StatusValue
from @Temp
group by StatusValue


Regards,
Bohra
Go to Top of Page

Nroblex
Starting Member

17 Posts

Posted - 2010-03-18 : 11:19:27
I did solve this using a unique NONCLUSTERED INDEX with Ignore_dup_key

thanks anyway
Go to Top of Page
   

- Advertisement -