0

Table : promocode

customerid   promocode
------------------------
1            123a-234b
2            123a
3            123a-234b-345c
4            23s-34f

I want result as

Promocode
--------------
123a,234b
123a
123a,234b,345c
23s,34f

plz help me ........

1
  • 1) Learn to speak some basic English. 2) Tell us more about your specific problem. What you wrote above does not allow me to help you in any way. Commented Nov 13, 2010 at 1:41

4 Answers 4

3

You can use REPLACE to change the hyphen character to a comma:

SELECT REPLACE(t.promocode, '-', ',')
  FROM PROMOCODE t

If you want to write this change to the table:

UPDATE PROMOCODE
   SET promocode = REPLACE(t.promocode, '-', ',')

If there's no hyphen, nothing is updated.

Reference:

Sign up to request clarification or add additional context in comments.

Comments

3
SELECT REPLACE(Promocode, '-', ',') AS Promocode FROM Promocode

Comments

2

SELECT REPLACE(promocode, '-', ',') 'promocode' FROM promocode

btw it is not very good practice to be naming your column to be the same name as your table!

Comments

1

Well as far as I can gather from your post, you want to replace "-" with ","

SELECT REPLACE(promocode, '-', ',') AS Promocode
  FROM MyTable

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.