Is there a way to remove all non-numeric characters from a nvarchar text string in MySQL?
I kind of got it working with the following select statement but I am having issues on getting the UPDATE statement so I can use the UPDATE on a MySQL trigger everytime something gets inserted or updated. I need to remove the dash "-" and any spaces and only leave all the numeric characters.
Here is a sample of the table structure.
http://sqlfiddle.com/#!2/90668/7/0
The field that contain all the dashes and the spaces is 'locationNumber'.
Thank you in Advance.
Related
I am trying to run the unload command on redshift to dump data from a table into a CSV file. This table has character and numeric fields. The character fields may contain a comma (,) , so I need quotes around them. However, I dont need quotes around my numeric columns.
The following command is the closest I have come, but cant seem to get rid of the quotes aroud my numeric data. How can I achieve the desired result?
unload ('select * from mytable') to
's3://mybucket/path/file.csv'
DELIMITER ',' ADDQUOTES
This results in data like:
"Henry, Jr","23","4.5"
"Henry, Sr","56","4.2"
What I would like is :
"Henry, Jr",23,4.5
"Henry, Sr",56,4.2
From reading the official documentation, it seems like that's not possible.
I can suggest two potential workarounds:
1) wrap your string columns with quotes in the query, i.e. instead of
select * from mytable
have
select int_col_1, int_col_2, '"'||str_col_1||'"','"'||str_col_2||'"' from mytable
2) export tab delimited files so the commas in text columns stop being a problem
I am loading a flat file into a SQL database. The flat file is comma delimited. Some of the column values have comma without being encapsulated in double quotes (for e.g - HPPV,TYRE). Now, when I try to use comma as text qualifier, I get a message saying column delimiter and text qualifier cannot be the same.
I want to somehow use comma as text qualifier so that the flat file keeps the value - HPPV,TYRE as on single entity - HPPVTYRE or HPPV TYRE, instead of spilling it over to the next column.
Is there any way we can use comma as text qualifier, it already being a column delimiter ?????
No, I don't think so but I searched and found this article that might help.
I have some faulty PHP code which inserted literal \r\n characters into the database instead of the special characters representing new line and carriage return. Can anyone help me come up with a query that will replace the literals with the special characters?
Here's an SQL Fiddle setup. All I really need is something that will return the row containing "abc\r\ndef" rather than the other row. It's probably a very simple escape that's needed, but I can't work it out.
http://sqlfiddle.com/#!9/1f2acb/1
Once I have that query I guess I will simply use
UPDATE test SET txt replace(txt, 'UNKNOWN EXPRESSIOn', '\r\n');
I'm running MySQL 5.5 on Ubuntu.
The answer was in a similar question that juanvan linked to.
UPDATE test set txt = replace(txt,'\\r\\n','\r\n');
My database has content that has been previously escaped, resulting in string such as
This value is \"invalid\".
I want to get rid of escape character \ but I'm having a hard time to find these rows. My first attempt
select value from content where value like '%\\"%';
fails to separate \" from ", and returns valid rows such as
This value is "valid".
So how can I query for the string \", preferably in a way than can be used in an update clause to remove the slash?
EDIT: SQL Fiddle here http://sqlfiddle.com/#!9/fc3d3/6
Notice that the query at line 3 returns both rows.
I've checked your sqlfiddle.
This gets the invalid rows:
SELECT * from myTable where content<>REPLACE(content,'\\\"','\"')
If this works, then you can simply update your content column to REPLACE(content,'\\\"','\"').
I'm trying to trim extraneous white space at the end of a memo field in MS Access. I've tried doing it a number of ways:
1) an update query with the field being updated to Trim([fieldname]). For some reason, that doesn't do anything. The whitespace is still there.
2) an update using a Macro function in which the field contents are passed as a String and then processed using the Trim() function and passed back. This one is really bizarre, in that it seems to truncate the text in the field at completely random places (different for each record). Sometimes 366 characters, sometimes 312, sometimes 280.
3) same as above but with RTrim()
How can I possibly be messing up such a simple function?! Any help much appreciated. Would like to keep my hair.
-Sam
According to this article:
Both Text and Memo data types store only the characters entered in a field; space characters for unused positions in the field aren't stored.
As hypoxide suggested, they may not in fact be spaces
Edit
I suspect that the last character in the field is a carriage return or linefeed character. If this is the case, then Trim (or any variations of Trim - RTrim\LTrim) won't work since they only remove space characters. As 'onedaywhen' suggested in the comment, try using the ASC function to determine the actual character code of the last character in the memo field. You can use something like the following in a query to do this:
ASC(Right(MyFieldName,1))
Compare the result of the query to the Character Set to determine the actual character that ends the memo field. (Space = 32, Linefeed = 10, Carriage Return = 13).
You may have to test the last character and if it is a linefeed or carriage return remove the character and then apply the trim function to the rest of the string.
This may date me, but does Access have different character types for fixed vs. variable lengths? in SQL, CHAR(10) will always by 10 chars long, padded if necessary, while VARCHAR(10) will be 'the' size up to 10. Truncating a CHAR(10) will just put the blanks back.