shamsuljewel Posted October 31, 2007 Share Posted October 31, 2007 I hv a table name table1 and column name col1 which contain data jewel,alam,etc so if i want to change jewel to shah that is col1 data will be shah,alam,etc how do I do it? what is the query? Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted October 31, 2007 Share Posted October 31, 2007 well try this update table1 set col1='shah' where col1='jewel' Quote Link to comment Share on other sites More sharing options...
shamsuljewel Posted October 31, 2007 Author Share Posted October 31, 2007 no col1 doesnot contain only jewel but jewel,alam,etc so this query doesnot match or find the jewel at col1 Quote Link to comment Share on other sites More sharing options...
fenway Posted October 31, 2007 Share Posted October 31, 2007 no col1 doesnot contain only jewel but jewel,alam,etc so this query doesnot match or find the jewel at col1 Do you want to change each of those values to a new value, or conditionally change each one? Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted October 31, 2007 Share Posted October 31, 2007 here you go pretty heavy but if you put in data that way you have to run some heavy queries to update it update table1 set col1 = REPLACE(REPLACE(REPLACE(ip,'jewel,','shah,'),',jewel',',shah'),',jewel,',',shah,') where col1 like 'jewel,%' or col1 like '%,jewel,%' or col1 like '%,jewel' Quote Link to comment Share on other sites More sharing options...
fenway Posted October 31, 2007 Share Posted October 31, 2007 Oh, it's comma-separated? Terrible... Quote Link to comment Share on other sites More sharing options...
shamsuljewel Posted November 3, 2007 Author Share Posted November 3, 2007 I want to change each value conditionally. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 3, 2007 Share Posted November 3, 2007 what do you mean conditionally ? Quote Link to comment Share on other sites More sharing options...
shamsuljewel Posted November 3, 2007 Author Share Posted November 3, 2007 that is I put some user_id those who are my friends in the column. So if I delete a user_id from the list then I just want to delete the specific user_id all the other remains same. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 3, 2007 Share Posted November 3, 2007 this should work for a delete update table1 set col1 = REPLACE(REPLACE(REPLACE(ip,'jewel,',''),',jewel',''),',jewel,',',') where col1 like 'jewel,%' or col1 like '%,jewel,%' or col1 like '%,jewel' this will delete all jewel enteries Quote Link to comment Share on other sites More sharing options...
shamsuljewel Posted November 3, 2007 Author Share Posted November 3, 2007 so If I want to add a new user_id to the column? can u please show me the query? Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 3, 2007 Share Posted November 3, 2007 you can try the following update table1 set col1=(CASE WHEN col1 is null THEN 'jewel' ELSE concat(col1,',','jewel') END) Quote Link to comment Share on other sites More sharing options...
shamsuljewel Posted November 3, 2007 Author Share Posted November 3, 2007 thanks for ur help....U solved my problems..thanks rajivgonsalves Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.