case condition

  • my query is :

    Select distinct CoveNoteNo,ProposerName,

    convert(decimal(18,2),FinalPremium) as finalpremium,

    p.ProductName as Product,ChqNo,ChqDate

    from DtlCvrNotePremium d with(nolock)

    inner join usrmgmt..usgi_product p with(nolock) on d.product=p.productvalue

    Where d.ChqNo is null and d.category='MO'

    now i there are some row in final premium which is null so final premium is not able to convert so i want that if row is null then also select with value 0 in that and not then display normally..

    FinalPremium is varchar field

  • Select distinct CoveNoteNo,ProposerName,

    convert(decimal(18,2),FinalPremium) as finalpremium,

    p.ProductName as Product,ChqNo,ChqDate

    from DtlCvrNotePremium d with(nolock)

    inner join usrmgmt..usgi_product p with(nolock) on d.product=p.productvalue

    Where d.ChqNo is null and d.category='MO'

    You can add a ISNULL filter and have 0 returned for null values. Try the below code if it fullfills your requirement:--

    Select distinct CoveNoteNo,ProposerName,

    convert(decimal(18,2),ISNULL(FinalPremium,0)) as finalpremium,

    p.ProductName as Product,ChqNo,ChqDate

    from DtlCvrNotePremium d with(nolock)

    inner join usrmgmt..usgi_product p with(nolock) on d.product=p.productvalue

    Where d.ChqNo is null and d.category='MO'

  • SELECT CONVERT(DECIMAL(18,2),NULL) AS finalpremium

    ...works just fine. What datatype is the column finalpremium?

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

Viewing 3 posts - 1 through 2 (of 2 total)

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