1

I am trying to make one table value function in Sql Server. Here I have 3 columns and i want to merge them into one column lets say "new". This new column should show the name of 3 columns if they have value as 1.For example for row one it should display Isprod, for row 2 it should display IsCompetProd and so on.

 IsProd IsCompetProd       IsOther
    1            0             0
    0            1             0
    0            0             1
    1            0             0

Is there any way to do that?

2
  • What have you tried so far? Please post your code in your question by editing it. Commented Mar 25, 2014 at 7:15
  • @shree.pat18 actually i searched it but couldn't figure out how to start it.. Commented Mar 25, 2014 at 7:19

2 Answers 2

1

Try like this

SELECT CASE WHEN IsProd=1 THEN 'IsProd'
            WHEN IsCompetProd=1 THEN 'IsCompetProd'
            WHEN IsOther=1  THEN 'IsOther'
        END [New]
FROM table1
Sign up to request clarification or add additional context in comments.

Comments

1

If I am getting what you want. Use a case statement. Try this:

SELECT
    tbl.*,
    (
    CASE 
        WHEN IsProd=1
        THEN 'IsProd'
        WHEN IsCompetProd=1
        THEN 'IsCompetProd'
        WHEN IsOther=1
        THEN 'IsOther'
        ELSE 'None'
    END 
    )AS newColumn       
FROM
    tbl

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.