Issue with CASE statement

  • SELECT

    ProductSkuTypeId = pst.[ProductSkuTypeID],

    ProductSkuTypeName = pst.[Name],

    p.ProductTaxCodeID,

    Here i am trying to write a case statement.

    like when the skutypename is Fab by default i have to set Tax Code as A_CLTH_FAB

    like when the skutypename is Notan by default i have to set Tax Code as A_CLTH_COMPON

    I tried to write like this..

    p.ProductTaxCodeID = CASE WHEN pst.Name IS Fab THEN A_CLTH_FAB

    WHEN pst.Name is Notan THEN A_CLTH_COMPON

    END,

    Will any one correct it if i am making mistake like to put Fab and default value in codes?

  • You have a few syntax mistakes, but the logic seems correct.

    SELECT ProductSkuTypeId = pst.[ProductSkuTypeID],

    ProductSkuTypeName = pst.[Name],

    ProductTaxCodeID = CASE WHEN pst.Name = 'Fab' THEN A_CLTH_FAB

    WHEN pst.Name = 'Notan' THEN A_CLTH_COMPON

    -- ELSE 'What?'

    END,

    ....

    FROM Somewhere

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • atlantageorgia123 (5/12/2015)


    SELECT

    ProductSkuTypeId = pst.[ProductSkuTypeID],

    ProductSkuTypeName = pst.[Name],

    p.ProductTaxCodeID,

    Here i am trying to write a case statement.

    like when the skutypename is Fab by default i have to set Tax Code as A_CLTH_FAB

    like when the skutypename is Notan by default i have to set Tax Code as A_CLTH_COMPON

    I tried to write like this..

    p.ProductTaxCodeID = CASE WHEN pst.Name IS Fab THEN A_CLTH_FAB

    WHEN pst.Name is Notan THEN A_CLTH_COMPON

    END,

    Will any one correct it if i am making mistake like to put Fab and default value in codes?

    Try:

    p.ProductTaxCodeID = CASE WHEN pst.Name = 'Fab' THEN 'A_CLTH_FAB'

    WHEN pst.Name = 'Notan' THEN 'A_CLTH_COMPON'

    END,



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

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

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