I want remove letters from my string like this:
select CAST(dstring as number), * from myTable
dstring can be M-St2, DE2, M12,
result should be 2, 2, 12
Thanks
I want remove letters from my string like this:
select CAST(dstring as number), * from myTable
dstring can be M-St2, DE2, M12,
result should be 2, 2, 12
Thanks
Replace the number in column. For example 'John12' delete '12' from column then return 'John', then replace 'John'. You can get '12'.
SELECT
REPLACE(dstring, REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE (
REPLACE( REPLACE( REPLACE( REPLACE(dstring ,'0','')
,'1',''),'2',''),'3',''),'4',''),'5',''),'6',''),'7',''),'8',''),'9',''), '')
FROM myTable;
Nailed it.... this will remove a-z and A-Z leaving all other characters behind...
UPDATE some_table SET some_field = REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE(some_field,'a','') ,'b','') ,'c','') ,'d','') ,'e','') ,'f','') ,'g','') ,'h','') ,'i','') ,'j','') ,'k','') ,'l','') ,'m','') ,'n','') ,'o','') ,'p','') ,'q','') ,'r','') ,'s','') ,'t','') ,'u','') ,'v','') ,'w','') ,'x','') ,'y','') ,'z','') ,'A','') ,'B','') ,'C','') ,'D','') ,'E','') ,'F','') ,'G','') ,'H','') ,'I','') ,'J','') ,'K','') ,'L','') ,'M','') ,'N','') ,'O','') ,'P','') ,'Q','') ,'R','') ,'S','') ,'T','') ,'U','') ,'V','') ,'W','') ,'X','') ,'Y','') ,'Z','');
And here's my PHP to generate that (add any other characters you need in the $to_remove string:
$to_remove = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$removals = str_split($to_remove,1);
$stmt = "some_field";
foreach($removals as $x) {
$stmt = " REPLACE(".$stmt.",'".$x."','') ";
}
$stmt = "update some_table set some_field = ".$stmt." ";
echo($stmt);
Try to do this code,it may helpfull to you.
dstring can be M-St2, DE2, M12,
result should be 2, 2, 12
only display numeric value.
SELECT NumericOnly(dstring) as number from myTable