Home > Software design >  Shorten a string inside an SQL Column
Shorten a string inside an SQL Column

Time:03-19

I need to shorten a string in a column inside a table and I'm not sure how to do that, and I'm sure it's super easy - I think it has something to do with UPDATE, but I can't solidify it.

Example "Table" below:

enter image description here

How can I just shorten the address to just "1462 Dragon Road"?

Thanks for your help!

CodePudding user response:

use following query

update yourtable 
set yourcolumn= SUBSTRING(yourcolumn,0, CHARINDEX(',',yourcolumn)) 
-- yourcolumn= LEFT(yourcolumn, CHARINDEX(',', yourcolumn, CHARINDEX(',', yourcolumn)) - 1) 

CodePudding user response:

I was able to shorten the string inside the table and column successfully using this method below:

UPDATE [table]
SET [column] = '[shortened value]'
WHERE [unique identifier for that row] = '[identifier]';
  • Related