Friday, March 23, 2012

Query for taking each word in a string, and putting a comma after it?

Hey all, i'm making the pages meta keywords on my site dynamic, and i was wondering is there is a string, for example "Dell 17" Monitor Brand New", that would split it into each word for the meta keywords. example "Dell, 17", Monitor, Brand, New" (and possibly to not put a comma on the last word?)

update myTable
set myField = Replace(myField, ' ', ' ,')

This will replace each space in your string and replace the space with a space + a comma.

I do the same thing (allowing for dynamic meta data) in my sites. However, I keep each word or phrase as a separate record in my db.
Then when I query for them I save them into an array and print array[0] + ", " array[1] + " ,"...

If you need to keep your data in it's original state than I suggest creating a temp table and modifying the temp table.

sql

No comments:

Post a Comment