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
 General SQL Server Forums
 New to SQL Server Programming
 select records within a range...

Author  Topic 

Topaz
Posting Yak Master

199 Posts

Posted - 2007-12-14 : 05:13:41
I currently use this query to select 4000 contacts from our database:

SELECT TOP 4000 * FROM wce_contact
where website not like ''
and expressemail like '%@%'
and idstatus like ''
and salutation not like '%there%'
and task not like '%x%'

So I use this query to send out emails, then I want the next set of contacts, so I am obv after the contacts 4001 to 8000. How would I right this into the above query?

Hope it all makes sense?

JT

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-12-14 : 05:17:11
"Hope it all makes sense?"

No it doesn't. TOP is only meaningful when you have ORDER BY clause. Since you are selecting TOP without ORDER BY, there is no guarantee which 4000 records it will pick, hence you can't start with 4001st record in next round.

Do you identity column in the table?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Topaz
Posting Yak Master

199 Posts

Posted - 2007-12-14 : 05:21:21
Well I run the query and find that everytime the same set of 4000 contacts turn up (ie the top 4000) and i was kind of hoping that this would happen throughout the query. eg move on to the next 4000 contacts...

So I guess I have to use the order by clause on the website field or something and from there how do i select the ranges?

Thanks
Go to Top of Page
   

- Advertisement -