doubt in CASE command

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • priyan
    New Member
    • Aug 2007
    • 54

    #1

    doubt in CASE command

    Hi all,
    I am having a table and there is a column named id. I have to choose the id and in case if id is null i have set id to '1' otherwise the same id should be displayed. For this i tried the following query but the result is not the proper one which i expect pls help me in this regard
    [code=sql]
    select substring(numbe r,2), case when substring(numbe r,2) is null then '1' else substring(numbe r,2) end as id from emp
    [/code]
    [code=text]
    substring id




    224 224
    [/code]
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    Originally posted by priyan
    Hi all,
    I am having a table and there is a column named id. I have to choose the id and in case if id is null i have set id to '1' otherwise the same id should be displayed. For this i tried the following query but the result is not the proper one which i expect pls help me in this regard
    [code=sql]
    select substring(numbe r,2), case when substring(numbe r,2) is null then '1' else substring(numbe r,2) end as id from emp
    [/code]
    [code=text]
    substring id




    224 224
    [/code]
    What does your table look like. Show data.

    Comment

    Working...