SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Constrain result set by unique code in query.
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

shimarli
Starting Member

1 Posts

Posted - 07/08/2013 :  21:28:47  Show Profile  Reply with Quote
Hi there..new to this. Pls be gentle.

Q. If I have a simple query like:

select * from bigtable
where product_code in ('abc','def','hij','klm')

I know that each of those product_codes will return a large data set. What I'd like to do is to run the same query but constrain the result set to a max rownum of 200.

Is this possible?

Thanks in advance...

MuMu88
Aged Yak Warrior

547 Posts

Posted - 07/09/2013 :  00:48:51  Show Profile  Reply with Quote
Try this:

SELECT * FROM 
(select ROW_NUMBER() OVER(PARTITION BY product_code order by product_code) AS RN, * from bigtable
where product_code in ('abc','def','hij','klm')) A
WHERE RN <= 200;
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.27 seconds. Powered By: Snitz Forums 2000