| Author | Topic | 
                            
                                    | gumubibiStarting Member
 
 
                                        6 Posts | 
                                            
                                            |  Posted - 2009-09-05 : 05:32:29 
 |  
                                            | HiI want to make an update query and I don't know how to make the query in this situation:I have a tableColumna1a2a3c1c2c3I want to transform c1 in a1, c2 in a2, c3 in a3 all this with one querry.Thank you |  | 
       
                            
                       
                          
                            
                                    | madhivananPremature Yak Congratulator
 
 
                                    22864 Posts | 
                                        
                                          |  Posted - 2009-09-05 : 06:07:15 
 |  
                                          | What is your expected result? select c from (	select 'a1' as  c union all	select 'a2' union all 	select 'a3' union all 	select 'c1' union all 	select 'c2' union all 	select 'c3') as t order by LEFT(c,1) desc,RIGHT(c,LEN(c)-1)MadhivananFailing to plan is Planning to fail |  
                                          |  |  | 
                            
                       
                          
                            
                                    | gumubibiStarting Member
 
 
                                    6 Posts | 
                                        
                                          |  Posted - 2009-09-05 : 09:27:21 
 |  
                                          | HiThank you but I don't really think this will help. I'm sorry that i was not that clear in the matter. The problem isColumn (names)ag. johnag. maryag. rogerca. johnca. maryca. rogerThe result I want to be is to transform ca. john as ag. john, ca. mary as ag. mary and ca. roger in ag. roger all in one update query.The simple way is to makeUpdate table set table. column(names)="ag.      "Where (((table.column(names))="ca.      "));for each name. |  
                                          |  |  | 
                            
                       
                          
                            
                                    | madhivananPremature Yak Congratulator
 
 
                                    22864 Posts | 
                                        
                                          |  Posted - 2009-09-05 : 10:14:10 
 |  
                                          | The simple way is to makeUpdate table set names=case when names like 'ca. ' then 'ag. '+substring(names,5,len(names)) else 'ca. '+substring(names,5,len(names)) endMadhivananFailing to plan is Planning to fail |  
                                          |  |  | 
                            
                       
                          
                            
                                    | webfredMaster Smack Fu Yak Hacker
 
 
                                    8781 Posts | 
                                        
                                          |  Posted - 2009-09-05 : 12:51:31 
 |  
                                          | update tableset names=replace(names,'ca. ','ag. 'where 'be_sure'+names like 'be_sureca. %' No, you're never too old to Yak'n'Roll if you're too young to die.
 |  
                                          |  |  | 
                            
                       
                          
                            
                                    | gumubibiStarting Member
 
 
                                    6 Posts | 
                                        
                                          |  Posted - 2009-09-05 : 14:07:52 
 |  
                                          | Thank you all for your answers but nothing works.Let put it in another wayNamesag. mariane vanzag. roger vanzag. jhonny vanzca. mariane vanzca. roger vanzca. jhonny vanzThe logical thinking is like that: if names is "ca. mariane vanz" then transform "ca. mariane vanz" in ag. mariane vanz; same goes for the rest. And I want all this transformation in one statement, update query. |  
                                          |  |  | 
                            
                       
                          
                            
                                    | webfredMaster Smack Fu Yak Hacker
 
 
                                    8781 Posts | 
                                        
                                          |  Posted - 2009-09-05 : 14:10:23 
 |  
                                          | So at the end there are two entries with ag. mariane vanz.My query does that! No, you're never too old to Yak'n'Roll if you're too young to die.
 |  
                                          |  |  | 
                            
                       
                          
                            
                                    | gumubibiStarting Member
 
 
                                    6 Posts | 
                                        
                                          |  Posted - 2009-09-05 : 14:14:07 
 |  
                                          | quote:??? I do not understand the be_sure thing. Can you help me a little bit with an example. And another thing. This must be done 3 times in our case with only one statement.Originally posted by webfred
 So at the end there are two entries with ag. mariane vanz.My query does that!
 No, you're never too old to Yak'n'Roll if you're too young to die.
 
 |  
                                          |  |  | 
                            
                       
                          
                            
                                    | webfredMaster Smack Fu Yak Hacker
 
 
                                    8781 Posts | 
                                        
                                          |  Posted - 2009-09-05 : 14:17:27 
 |  
                                          | [code]-- creating sample tabledeclare @yak table (names varchar(25))-- insert sample datainsert @yakselect 'ag. mariane vanz' union allselect 'ag. roger vanz' union allselect 'ag. jhonny vanz' union allselect 'ca. mariane vanz' union allselect 'ca. roger vanz' union allselect 'ca. jhonny vanz'-- diplay sample dataselect * from @yak-- output:/*names-------------------------ag. mariane vanzag. roger vanzag. jhonny vanzca. mariane vanzca. roger vanzca. jhonny vanz*/------------------ do the update----------------update @yakset names=replace(names,'ca. ','ag. ')where 'be_sure'+names like 'be_sureca. %'-- display the new valauesselect * from @yak-- output:/*names-------------------------ag. mariane vanzag. roger vanzag. jhonny vanzag. mariane vanzag. roger vanzag. jhonny vanz*/[/code] No, you're never too old to Yak'n'Roll if you're too young to die.
 |  
                                          |  |  | 
                            
                       
                          
                            
                                    | webfredMaster Smack Fu Yak Hacker
 
 
                                    8781 Posts | 
                                        
                                          |  Posted - 2009-09-05 : 14:23:02 
 |  
                                          | I have concatenated the string 'be_sure' only to prevent the replace command from replacing too much.For example'ac. yakidiyak' would not be a problem to replace 'ac. ' by 'ag. ''ac. yaki ac. di ac. yak' would be a problem because we want only the first 'ac. ' to be replaced.So my statement  gives 'be_sureac. ' to the replace command for the string 'be_sureac. yaki ac. di ac. yak' and hence only the first value will be changed. No, you're never too old to Yak'n'Roll if you're too young to die.
 |  
                                          |  |  | 
                            
                       
                          
                            
                                    | webfredMaster Smack Fu Yak Hacker
 
 
                                    8781 Posts | 
                                        
                                          |  Posted - 2009-09-05 : 14:24:28 
 |  
                                          | Look at my sample there are 3 changes made in one go - is that ok? No, you're never too old to Yak'n'Roll if you're too young to die.
 |  
                                          |  |  | 
                            
                       
                          
                            
                                    | gumubibiStarting Member
 
 
                                    6 Posts | 
                                        
                                          |  Posted - 2009-09-05 : 14:26:52 
 |  
                                          | quote:Thank youOriginally posted by webfred
 
 -- creating sample tabledeclare @yak table (names varchar(25))-- insert sample datainsert @yakselect 'ag. mariane vanz' union allselect 'ag. roger vanz' union allselect 'ag. jhonny vanz' union allselect 'ca. mariane vanz' union allselect 'ca. roger vanz' union allselect 'ca. jhonny vanz'-- diplay sample dataselect * from @yak-- output:/*names-------------------------ag. mariane vanzag. roger vanzag. jhonny vanzca. mariane vanzca. roger vanzca. jhonny vanz*/------------------ do the update----------------update @yakset names=replace(names,'ca. ','ag. ')where 'be_sure'+names like 'be_sureca. %'-- display the new valauesselect * from @yak-- output:/*names-------------------------ag. mariane vanzag. roger vanzag. jhonny vanzag. mariane vanzag. roger vanzag. jhonny vanz*/ No, you're never too old to Yak'n'Roll if you're too young to die.
 
 |  
                                          |  |  | 
                            
                       
                          
                            
                                    | webfredMaster Smack Fu Yak Hacker
 
 
                                    8781 Posts | 
                                        
                                          |  Posted - 2009-09-05 : 14:28:06 
 |  
                                          | welcome  No, you're never too old to Yak'n'Roll if you're too young to die.
 |  
                                          |  |  | 
                            
                       
                          
                            
                                    | gumubibiStarting Member
 
 
                                    6 Posts | 
                                        
                                          |  Posted - 2009-09-05 : 15:02:17 
 |  
                                          | Just to make the topic more interesting and complete for other interested forum members how about 2 separate definitions like:Namesag. jhonny vanzagent mary vanzca. jhonny vanzca. mary vanzThe question is the same. Update query for the transformation of "ca. jhonny vanz" into "ag. jhonny vanz" and "ca. mary vanz" into "agent mary vanz" in one statement. |  
                                          |  |  | 
                            
                            
                                |  |