Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Result Set


Result Set

Author
Message
lax.rawat07
lax.rawat07
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
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
Henrico Bekker
Henrico Bekker
SSCrazy
SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)

Group: General Forum Members
Points: 2029 Visits: 3255
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.
goodguy
goodguy
SSC Veteran
SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)

Group: General Forum Members
Points: 292 Visits: 1037
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

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search