Sql Query

  • Hello Everyone,

    i have a table like as follows

    CustId       InvID        Amount       BillAmt     isRegularCust

    1                1               100        10             1

    1                1               500        150            0

     

     

    and i want output like as follows

    CustId        InvId       AmountRegulare         AmountNotRegular          BillingAmt

    1                1             100                        NULL                            10

    1                1             NULL                      500                               150

     

    Please send me sql query for getting this output.              

  • Not too hard and perfect for CASE. Try this

    SELECT CustID, InvID,

     CASE isRegularCustomer WHEN 1 THEN Amount ELSE NULL END AS AmountRegular,

     CASE isRegularCustomer WHEN 0 THEN Amount ELSE NULL END AS AmountNotRegular,

     BillingAmt

    FROM CustomerTable.

    Hope that helps.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Hi all,

     

    I want result in one select of following table as below:

     

    RowID              Message          MessageType

    1                     To               ‘some name’

    2                     From           ‘My Name’

    3                     To               ‘some other name’

    4                     Cc              ‘some CC name’

    5                     BCC           ‘some BCC Name’

    6                     UserBCC     ‘some UserBCC name’

     

    Results should be as:

     

     

    To                                            From                            CC                                BCC                             UserBCC

    some name; some other name’   My Name                      some CC name’             some BCC name’           some UserBCC name’

     

     

    I know well I can do this via stored procedure, but I think it can be some using Pivot features of SQL Server 2005. Plz help me solving this as soon as possible.

     

    Thanks in advance.

    Shamshad Ali

  • Could you please start your own thread for this. You'll get more replies and reads than if you hijack another.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thanks for suggestion, I have opended a new Thread for help.

    Plz help me solving my query.

    Thanks once again.

     

    Shamshad Ali

Viewing 5 posts - 1 through 4 (of 4 total)

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