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
 Transact-SQL (2005)
 Selecting always two rows from the table

Author  Topic 

shakthiA
Starting Member

12 Posts

Posted - 2009-10-16 : 04:25:01
Hi

I want to select always two rows from our tables on top besides the results that I get from my search.

I was doing some thing like below code if I want to have one row from our tables on top results. Now I need to change this for 2 rows which could not done with UNION and two Case statements.

SELECT * FROM
(
SELECT ROW_NUMBER() OVER (ORDER BY CASE WHEN S.ID = '4ed975f8' THEN 0 ELSE 1 END, (SELECT Rank FROM #tmpLangs WHERE Lang = S.Language COLLATE SQL_Latin1_General_CP1_CI_AS) DESC,S.CreationDate DESC) AS Row,
S.Language,
S.ID AS 'PubId'
FROM
SHELF S
, Featured FP
WHERE
FP.ID = P.ID
AND S.Audience = 'Public'

)AS FeaturedPubs
WHERE Row BETWEEN 1 AND 10

Any Ideas Please help me.

Thanks

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-10-16 : 05:26:34
SELECT TOP 2 * FROM...

or waht do you mean?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

shakthiA
Starting Member

12 Posts

Posted - 2009-10-16 : 06:23:45

Sample Output I want to have like :

Row Lang PubId Title
1 en 4ed975f8 dddddd
2 70066abc 10.15.2009
3 ba738703 bentley
4 ccccccc test test
5 de bbbbbbb yami


Now it returns for me like below:

Row Lang PubId Title
1 en 4ed975f8 dddddd
2 ba738703 bentley
3 70066abc 10.15.2009
4 ccccccc test test
5 de bbbbbbb yami

If I want to have always this second document next to the first one I need to have a script to select the both documents first and then others.

Thanks.

quote:
Originally posted by webfred

SELECT TOP 2 * FROM...

or waht do you mean?


No, you're never too old to Yak'n'Roll if you're too young to die.

Go to Top of Page
   

- Advertisement -