You must Sign In to post a response.
  • Category: SQL Server

    Compare two amount in column in Sql Server Query

    I want to compare two amount column.Column Name is (1)camount(Contract Amount) (2) paymenttilldate(Payment Till Date Amount)
    If Contact Amount is Equal to Payment Till Date Amount Then Remaining Days will not calculate means it show blank .
    If Contact Amount is Greater Than or Less Than to Payment Till Date Amount Then Remaining Days will calculate menas Remaining days will shows.
    My Query is Given below:
    select contractno,camount, (ISNULL (sum(ActualPayment + AdvanceAdjustment),0)) as paymenttilldate,
    (CASE WHEN tbl_contract.RevisedDate IS NULL or tbl_contract.RevisedDate=''
    THEN CONVERT(varchar, DATEDIFF(DAY,getdate(),tbl_contract.edate))
    else CONVERT(varchar,DATEDIFF(DAY,getdate(),tbl_contract.RevisedDate))end) as RemainingDay
    from tbl_contract
    left join tbl_ContractAmountMileStone on tbl_ContractAmountMileStone.ContractId= tbl_contract.contractid --Add 3 Aug 2015 For payment Till date
    where tbl_contract.contractid=11115

    group BY camount,tbl_contract.contractid,tbl_contract.contractno,tbl_contract.RevisedDate,tbl_contract.edate
    order by contractno
  • #761202
    Hi
    Nitin

    Can you provide proper table structure with sample Data for this then participants easily solve in your issues

    What is your issue can you explain more.

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #761304
    Hi

    You can try this Query


    select contractno,CASE WHEN camount= (ISNULL (sum(ActualPayment + AdvanceAdjustment),0)) THEN
    (CASE WHEN tbl_contract.RevisedDate IS NULL or tbl_contract.RevisedDate=''
    THEN CONVERT(varchar, DATEDIFF(DAY,getdate(),tbl_contract.edate))
    else CONVERT(varchar,DATEDIFF(DAY,getdate(),tbl_contract.RevisedDate))end) as RemainingDay
    ELSE 'Else statement' END as paymenttilldate
    from tbl_contract
    left join tbl_ContractAmountMileStone on tbl_ContractAmountMileStone.ContractId= tbl_contract.contractid --Add 3 Aug 2015 For payment Till date
    where tbl_contract.contractid=11115

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.


Sign In to post your comments