From: AnilKumar via SQLMonster.com on
hello, everyone
Help needed in query
i have a table which have three field

tabId tabPrtId tabSlab
1 11 50
2 11 100
3 11 150
4 11 200

tabId Is table id it is key also
tabPrtId Is Party id in table
tabSlab Is slab value

now i want result like

tabPrtId slabFrom slabTo
11 50 100
11 100 150
11 150 200

means

for a particular party id i want to create slabs range -- from and to

thanks & Regards

Anil Kumar

--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-programming/201008/1

From: Stefan Hoffmann on
hi Anil,

On 03.08.2010 14:24, AnilKumar via SQLMonster.com wrote:
> hello, everyone
> Help needed in query
> i have a table which have three field
>
> tabId tabPrtId tabSlab
> 1 11 50
> 2 11 100
> 3 11 150
> 4 11 200
>
> tabId Is table id it is key also
> tabPrtId Is Party id in table
> tabSlab Is slab value
>
> now i want result like
>
> tabPrtId slabFrom slabTo
> 11 50 100
> 11 100 150
> 11 150 200
>
> means
>
> for a particular party id i want to create slabs range -- from and to
E.g.

SELECT
O.tabPrtId,
O.tabSlab AS slabFrom,
(
SELECT Min(tabSlab)
FROM yourTable I
WHERE I.tabPrtId = O.tabPrtID
AND I.tabSlab > O.tabSlab
) AS slabTo
FROM yourTable O
ORDER BY tabSlab;


mfG
--> stefan <--
From: AnilKumar via SQLMonster.com on
Stefan Hoffmann wrote:
>hi Anil,
>
>> hello, everyone
>> Help needed in query
>[quoted text clipped - 20 lines]
>>
>> for a particular party id i want to create slabs range -- from and to
>E.g.
>
>SELECT
> O.tabPrtId,
> O.tabSlab AS slabFrom,
> (
> SELECT Min(tabSlab)
> FROM yourTable I
> WHERE I.tabPrtId = O.tabPrtID
> AND I.tabSlab > O.tabSlab
> ) AS slabTo
>FROM yourTable O
>ORDER BY tabSlab;
>
>mfG
>--> stefan <--


Sir Stefan Hoffmann

Thank You very much
its grate, its working very well

thanks & regards

Anil Kumar

--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-programming/201008/1