Eliminar ciertos caracteres de una cadena
Estoy tratando de eliminar ciertos caracteres.
En este momento tengo salida como cityname district
pero quiero eliminar cityname
.
SELECT Ort FROM dbo.tblOrtsteileGeo
WHERE GKZ = '06440004'
Salida:
Büdingen Aulendiebach
Büdingen Büches
Büdingen Calbach
Büdingen Diebach
Büdingen Dudenrod
Büdingen Düdelsheim
Salida deseada:
Aulendiebach
Büches
Calbach
Diebach
Dudenrod
Düdelsheim
38
Author: Aaron Bertrand, 2013-01-14
3 answers
Puede usar la función Replace
como;
REPLACE ('Your String with cityname here', 'cityname', 'xyz')
--Results
'Your String with xyz here'
Si aplica esto a una columna de tabla donde stringColumnName, cityName both are columns of YourTable
SELECT REPLACE(stringColumnName, cityName, '')
FROM YourTable
O si desea eliminar 'cityName'
cadena de salida puesto de una columna entonces
SELECT REPLACE(stringColumnName, 'cityName', '')
FROM yourTable
EDIT: Dado que ha dado más detalles ahora, la función REPLACE
no es el mejor método para ordenar su problema. Seguir es otra forma de hacerlo. También @MartinSmith ha dado una buena respuesta. Ahora usted tiene la opción de seleccionar de nuevo.
SELECT RIGHT (O.Ort, LEN(O.Ort) - LEN(C.CityName)-1) As WithoutCityName
FROM tblOrtsteileGeo O
JOIN dbo.Cities C
ON C.foo = O.foo
WHERE O.GKZ = '06440004'
72
Author: Kaf,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-01-14 14:27:13
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-01-14 14:27:13
Un problema con REPLACE
será donde los nombres de las ciudades contienen el nombre del distrito. Puedes usar algo así.
SELECT SUBSTRING(O.Ort, LEN(C.CityName) + 2, 8000)
FROM dbo.tblOrtsteileGeo O
JOIN dbo.Cities C
ON C.foo = O.foo
WHERE O.GKZ = '06440004'
7
Author: Martin Smith,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-01-14 13:37:46
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-01-14 13:37:46
UPDATE yourtable
SET field_or_column =REPLACE ('current string','findpattern', 'replacepattern')
WHERE 1
-2
Author: Namjoo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-12 10:03:25
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-12 10:03:25