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.
Author |
Topic |
Jomypgeorge
Starting Member
31 Posts |
Posted - 2010-08-05 : 02:54:35
|
hi all, i have to fetch data from a tax table having taxname, itemname, tax percentage as fields. each item may have any number of tax entered in it. but i have to fetch a given number of tax for each item.create table #tax (tax nvarchar(50), item nvarchar(50), percentge smallint )insert into #tax values ('Tax1', 'Item1', 10)insert into #tax values ('Tax1', 'Item2', 20)insert into #tax values ('Tax1', 'Item3', 30)insert into #tax values ('Tax2', 'Item2', 15)insert into #tax values ('Tax2', 'Item3', 17)insert into #tax values ('Tax2', 'Item4', 8)insert into #tax values ('Tax3', 'Item1', 12)insert into #tax values ('Tax3', 'Item3', 10)insert into #tax values ('Tax3', 'Item4', 19)I have to fetch at most two taxes for each item in this table.How to achieve this in query? |
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-08-05 : 03:07:14
|
Expected output?Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
Sachin.Nand
2937 Posts |
Posted - 2010-08-05 : 03:19:43
|
[code]select tax,item,percentge from(select *,row_number()over(partition by item order by percentge desc)as rid from #tax t1)t where rid between 1 and 2[/code]Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless. PBUH |
 |
|
Jomypgeorge
Starting Member
31 Posts |
Posted - 2010-08-05 : 04:59:57
|
i got what i really needed.thanks Idera. |
 |
|
Sachin.Nand
2937 Posts |
Posted - 2010-08-05 : 05:05:17
|
quote: Originally posted by Jomypgeorge i got what i really needed.thanks Idera.
WelcomeLimitations live only in our minds. But if we use our imaginations, our possibilities become limitless. PBUH |
 |
|
|
|
|
|
|