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 2000 Forums
 Transact-SQL (2000)
 How do I retrieve a set of fields that have a particular field value in the middle?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-02-07 : 10:13:45
Andrew writes "Basically I want to produce a list of fields, where this list contains a particular known field value in the middle of the list.

So if my field value is 'blue', I want to return the preceeding 5 records, the value I know, and then the following 5 records, according to the order by clause e.g.

red, green, yellow, orange, BLUE, black, pink, lilac, purple, violet

Any ideas?"

chadmat
The Chadinator

1974 Posts

Posted - 2002-02-07 : 13:21:31
Well,

With the limited information, I will give it a try. I am probably way off, because I don't know what your tables or your data look like.

How about

select top 5 color from colortable
order by color desc
UNION
select 'blue'
UNION
select top 5 color from colortable
order by color asc

-Chad


Go to Top of Page
   

- Advertisement -