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
 Other SQL Server Topics (2005)
 Sql query select rows 10-20

Author  Topic 

taunt
Posting Yak Master

128 Posts

Posted - 2011-10-04 : 18:25:04
Hello I'm trying to do a select query in MSSMS 2005 and I need it to select rows 10-20. Any info would be great. Need it to select rows 10-20 from upc in items.

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-10-04 : 21:17:35
Take a look at the ROW_NUMBER() function.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-05 : 00:55:23
you need totally 10-20 rows or 10-20 rows for each upc?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

taunt
Posting Yak Master

128 Posts

Posted - 2011-10-05 : 11:41:12
quote:
Originally posted by tkizer

Take a look at the ROW_NUMBER() function.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog



I;ve tried ROW_NUMBER() and it kills SSMS. I'm on sp4 and I think there's issues with ROW_NUMBER() after sp3. Least I can't get it to work. Is there anything else I could try?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-10-05 : 11:53:00
ROW_NUMBER() works fine on all service packs. We are on SP3 on some systems and SP4 on other systems, it works fine on each of them.

Maybe you are returning too much data? Show us the code.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

taunt
Posting Yak Master

128 Posts

Posted - 2011-10-05 : 12:08:44
quote:
Originally posted by tkizer

ROW_NUMBER() works fine on all service packs. We are on SP3 on some systems and SP4 on other systems, it works fine on each of them.

Maybe you are returning too much data? Show us the code.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog



SELECT upc, ROW_NUMBER() OVER (ORDER BY upc DESC) AS RowNumber
FROM items
where sku like 'zzz[0-9]%'

When I do that with SSMS it will freeze then after 30 seconds say an error occurred SSMS has to shut down.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-10-05 : 12:28:39
What does this return:

SELECT count(*)
FROM items
where sku like 'zzz[0-9]%'

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

taunt
Posting Yak Master

128 Posts

Posted - 2011-10-05 : 13:01:32
quote:
Originally posted by tkizer

What does this return:

SELECT count(*)
FROM items
where sku like 'zzz[0-9]%'

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog


Count works, but row_number doesn't.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-10-05 : 13:17:49
But what does the count return?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-06 : 01:40:16
quote:
Originally posted by taunt

quote:
Originally posted by tkizer

What does this return:

SELECT count(*)
FROM items
where sku like 'zzz[0-9]%'

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog


Count works, but row_number doesn't.


That we know
intention of asking this was to understand amount of data you're dealing with.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -