Query Help - using 2 Column update 3rd column

  • here is the Result column i updated like

    penspencils result

    4 2 4pens / 2pencils

    5 6 5pens /6Pencils

    1 0 1pen

    0 3 3pencils

    Can any one please help me to write the script PLease

  • Home work question

    🙂

    Create table #PenPencil (Pen int, Pencil int)

    go

    Insert into #PenPencil

    select 4,2

    union

    select 5,6

    union

    select 1,0

    union

    select 0,3

    select

    Case when Pen > 0 then 'Pens'

    When Pen =1 then 'Pen'

    Else '' End + Case when Pen > 0 and Pencil > 0 then '/' Else '' End +

    Case when Pencil > 0 then 'Pencils'

    When Pencil =1 then 'Pencil'

    Else '' End from #PenPencil

  • Missed printing the number of items for pens and pencils.

    Updated one.

    Create table #PenPencil (Pen int, Pencil int)

    go

    Insert into #PenPencil

    select 4,2

    union

    select 5,6

    union

    select 1,0

    union

    select 0,3

    select

    Case when Pen > 1 then convert(varchar,pen) + ' Pens'

    When Pen =1 then convert(varchar,pen) + ' Pen'

    Else '' End + Case when Pen > 0 and Pencil > 0 then '/' Else '' End +

    Case when Pencil > 1 then convert(varchar,pencil) + ' Pencils'

    When Pencil =1 then convert(varchar,pencil) + ' Pencil'

    Else '' End from #PenPencil

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

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