Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
JeffS23
Posting Yak Master
212 Posts |
Posted - 2008-01-04 : 12:52:12
|
I have a colum in sql and I need to remove the middle inital which appears at the end of the string and there is a space between the last name and the middle inital. Braeden M How can I get it so that on the Braeden is written to the column. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-01-04 : 12:59:11
|
SELECTCASEWHEN CHARINDEX(' ',Column,LEN(Column)-1)>0 THEN LEFT(Column,CHARINDEX(' ',Column,LEN(Column)-1)-1)ELSE ColumnENDFROM TABLE |
 |
|
JeffS23
Posting Yak Master
212 Posts |
Posted - 2008-01-04 : 14:47:01
|
this gives me the error subquery returned more than 1 value. Thanksupdate upload set lname = (SELECTCASEWHEN CHARINDEX(' ',lname,LEN(lname)-1)>0 THEN LEFT(lname,CHARINDEX(' ',lname,LEN(lname)-1)-1)ELSE lnameENDFROM upload) |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-01-04 : 15:06:10
|
There's no reason to use it as a subquery. Try this:update upload set lname = CASE WHEN CHARINDEX(' ',lname,LEN(lname)-1)>0 THEN LEFT(lname,CHARINDEX(' ',lname,LEN(lname)-1)-1)ELSE lnameENDTara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
|
|
|
|