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)
 include different values for set of rows in select

Author  Topic 

chodanvaibhav
Starting Member

4 Posts

Posted - 2009-02-02 : 04:21:39
i am fetching 20 rows and i want for first 5 rows to include one more column say size for which value will be 20 and for next should be 15 and next 5 10 and so no .i don't know how to do it please help me out

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-02 : 04:24:44
[code]
select *,20/((ROW_NUMBER() OVER(ORDER BY PK)-1) /5 + 1)
FROm YourTable
[/code]
Go to Top of Page

chodanvaibhav
Starting Member

4 Posts

Posted - 2009-02-02 : 04:46:43
Thanks for the reply but thing is that row nos might be anynthing just for ex i specified 20 and one more thing i am using order by
i had included query below

select FT.Tag +''(''+ cast(count(FATM.TagId) as varchar(2))+'')'' tags,
count(FATM.TagId) tagCount,
TagId,
(select InstituteShortName from Organisation O inner join UserOrgMapping UOM on O.ID=UOM.OrgID where UOM.UserID='+ cast(@userId as varchar(20))+')InstShrtName
from Forum_Tags FT inner join Forum_ArticleTitle_Tag_Mapping FATM on FT.ID =FATM.TagId
group by FATM.TagId,FT.Tag
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-02 : 08:41:28
sorry didnt get that. can you explain with some data?
what i've done is to generate row number at run time and then determine the number based on it so it will work even if your key does not contain consecutive values.
Go to Top of Page
   

- Advertisement -