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.
| Author |
Topic |
|
marioab
Starting Member
2 Posts |
Posted - 2007-03-16 : 08:00:15
|
| Hi,i need to do a select on which i have to process one record just when the result of this select returns me only one row, if the select returnme more than one this selection will be rejected. I have tried to do something like:select count(*) from (select top 2 * from table1 where condition)but it was not successful. I need this query have a really good performance also.Is this possible? Thanks in advance. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-16 : 08:32:06
|
| select count(*) from (select top 2 * from table1 where condition) as dPeter LarssonHelsingborg, Sweden |
 |
|
|
marioab
Starting Member
2 Posts |
Posted - 2007-03-16 : 09:06:00
|
| Thanks so much!!! it works. Is this the best way to get data? or there is a better solution to improve the performance? Thanks again!!! |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-16 : 09:19:02
|
| I think this might be a little faster. I haven't tested it.[code]SET ROWCOUNT 2declare @items intSELECT @Items = COUNT(*) from table1 where {condition}SET ROWCOUNT ONif @items <> 1 return-- do real stuff herePeter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|