How can i get this output ??

  • Dear all,

    How can i get the following result using below details ?

    The table have the data like below

    INPUT:(Table's data)

    id curre rate

    1 USD 4.2

    2 INR 5.6

    3 usd 5.2

    I want the result.

    RESULT:

    Id USD IND

    1 4.2 0

    2 0 5.6

    3 5.2 0

    please help me....

    Regards

    Mohanaraj.

  • [font="Verdana"]

    try this

    Selectid

    ,USD = (Case When Curre = 'usd' Then Rate Else 0 End)

    ,INR = (Case When Curre = 'inr' Then Rate Else 0 End)

    FromTable

    --Mahesh

    [/font]

    MH-09-AM-8694

  • You can also use PIVOT operator. Here is the example

    select id, USD = ISNull([USD], 0), IND = IsNull([IND], 0)

    From

    (

    Select id, Curr, rate

    from Table

    ) AS Tb

    Pivot

    (

    Sum(Rate)

    For Curr in ([USD], [IND])

    ) As Pv

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply