473,320 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Find and replace query in SQL server

I want to chane my name column records like if the name is with one word (Example: John) it shuold remain same (Ex: John). If it is with two words (Ex: John Bodi) it should be there as it is (Ex: John Bodi) but if it is one word and one letter (Ex:John B) then it should get '.' at the end of the letter(Ex: John B.)
Please post your query for this. It helps me.
Apr 16 '14 #1
2 1341
Hi,
Try this:
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE dbo.tblNames 
  2. (
  3.     ID int,
  4.     FName varchar(25),
  5.     LName varchar(25)
  6. GO
  7.  
  8. INSERT INTO tblNames 
  9.      VALUES (1, 'John', 'Doe')
  10. INSERT INTO tblNames 
  11.      VALUES (2, 'Jack', 'B')
  12. INSERT INTO tblNames 
  13.      VALUES (3, 'S', 'Fry')
  14. INSERT INTO tblNames 
  15.      VALUES (4, 'H', 'M')
  16. GO
  17.  
  18. SELECT * FROM tblNames
  19. GO
  20.  
  21. UPDATE tblNames SET 
  22.     FName = CASE WHEN LEN(FName) = 1 THEN (FName + '.') ELSE FName END,
  23.     LName = CASE WHEN LEN(LName) = 1 THEN (LName + '.') ELSE LName END
  24. GO
  25.  
  26. SELECT * FROM tblNames
  27.  
  28. GO
  29. DROP TABLE tblNames
  30.  
  31.  
Apr 16 '14 #2
Thank you so much! It helped me alot.

@landrew21
May 2 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: William Logan | last post by:
Hello all DBAs what is the best methodolgy to replace a server with a new server in a multiple sql server environment.. Is is using back up/restore to another/bridge type server then rename...
4
by: JackRazz | last post by:
I'm trying to use Visual Studio's Find/Replace to match VB declarations. This RegEx works fine in Regulator: ...
2
by: :\\\\derian | last post by:
anyone know where i could find the equivalent of the find / replace windows control for my project? :\\derian
2
by: scorpion53061 | last post by:
This excel find/replace code works great under Excel 2003 but bombs with an error (pasted below the code) in Excel 2000. Can anyone suggest an alternative to make both happy? I am using vb.net...
0
by: D Brown | last post by:
Does anyone know why my .NET development would hang / freeze when performing a Global Find / Replace on all files? I have a large ASP.NET VB Application. I have left the machine for 24 hours but...
0
by: vipal.keshwala | last post by:
I just migrated the access data base onto a new server but when I open the application up and click on find/replace in the find what field I try to right click a paste some information, but the...
0
by: Scott | last post by:
Ok I am using the code below to set the default find option but it does not seem to stick. I query the option with getoptions and it is set to 1 but when the find dialog opens it still is set to...
8
by: John Pye | last post by:
Hi all I have a file with a bunch of perl regular expressions like so: /(^|)\*(.*?)\*(|$)/$1'''$2'''$3/ # bold /(^|)\_\_(.*?)\_\_(|$)/$1''<b>$2<\/ b>''$3/ # italic bold...
4
by: vimalvisves | last post by:
Hi Friends, Any one know how to replace query string by slash delimeters, for example i want to replace query string www.websiteurl.com/PageName.aspx?Param1=Attribute1&Param2=Attribute2 as...
4
by: Elliot Fraval | last post by:
Hi All, Environment is VBA code in Access 2007. I am having some problems performing a find and replace on text that originates from a memo field in a table. The code is supposed to take...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.