|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, November 09, 2010 11:55 PM
Points: 1,
Visits: 0
|
|
i have a result set
LedgerId, ProfitAndLoss
46 -3000.00 49 -7000.00 45 15000.00
I want Result Set As
LedgerId, ProfitAndLoss Result
46 -3000.00 Credit 49 -7000.00 Credit 45 15000.00 Debit
Please help me ProfitAndLoss Is a Decimal field and we have to separated by minus value
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 2:24 AM
Points: 1,871,
Visits: 2,692
|
|
lax.rawat07 (11/10/2010) i have a result set
LedgerId, ProfitAndLoss
46 -3000.00 49 -7000.00 45 15000.00
I want Result Set As
LedgerId, ProfitAndLoss Result
46 -3000.00 Credit 49 -7000.00 Credit 45 15000.00 Debit
Please help me ProfitAndLoss Is a Decimal field and we have to separated by minus value
you can try using your 3rd column as a computed column. if Profitandloss < 0 then 'Credit' ELSE 'Debit'
---------------------------------------------- Msg 8134, Level 16, State 1, Line 1 Divide by zero error encountered.
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Monday, October 01, 2012 3:30 PM
Points: 292,
Visits: 1,028
|
|
lax.rawat07 (11/10/2010) i have a result set
LedgerId, ProfitAndLoss
46 -3000.00 49 -7000.00 45 15000.00
I want Result Set As
LedgerId, ProfitAndLoss Result
46 -3000.00 Credit 49 -7000.00 Credit 45 15000.00 Debit
Please help me ProfitAndLoss Is a Decimal field and we have to separated by minus value
You can set this extra field with a case statement in your SELECT query as such: SELECT LEDGERID, PROFITANDLOSS, RESULT = CASE WHEN PROFITANDLOSS <= 0 THEN CREDIT ELSE DEBIT END FROM MYTABLE
OR, you can add a calculated field to your underlying table.
Regards,
goodguy
Experience is a bad teacher whose exams precede its lessons
|
|
|
|