Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Result Set Expand / Collapse
Author
Message
Posted Wednesday, November 10, 2010 12:00 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, November 9, 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
Post #1018387
Posted Wednesday, November 10, 2010 1:14 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 9:53 AM
Points: 1,904, Visits: 2,822
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.
Post #1018403
Posted Wednesday, November 10, 2010 1:16 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, October 1, 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

Post #1018404
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse