Remove All data in string after 10th entry - mysql

I have this data in a string 0871234567ThisPartOfTheStringIsRandom
How Do I update the string to just keep the first 10 Chars?
Please Keep in mind I have thousands of entries where 'ThisPartOfTheStringIsRandom' is different in every case

The LEFT function is a string function that returns the left part of a string with a specified length.
UPDATE TableA
SET YourColumn = LEFT(YourColumn,10)

Related

Display a column values in Report Header

need to pass one column in Lookupset and I am doing as below
="Billing Code: "+Code.JoinDistinct(LookupSet(Fields!BillingCode.Value, Fields!BillingCode.Value, Fields!BillingCode.Value, "DataSet1"),",")
and the Function is
public shared function JoinDistinct(
dups as object(),
delimiter as string
) as string
dim result as string = ""
system.array.sort(dups)
for i as integer = 0 to dups.length - 1
if i <> 0 then result += delimiter
if i = 0 orElse dups(i) <> dups(i-1) then result += dups(i)
next i
return result
end function
Result
Billing Code: ,,,A,,,,,,
How Can I remove extra commas
What you're trying to do is certainly possible, but requires a bit of a workaround. The Join function is designed to work on an array of values. The column you used, even though it may have multiple rows at that scope, is not an array. You can use the LookupSet function to get the rows as an array and pass them into the Join function. If there may be duplicate values that you want to remove, you'll have to add custom code to handle that.
Here's an example of how to do that: https://stackoverflow.com/a/27141955/2033717
Let me know if this answers your question.

remove part of string record in mysql

this is my string record on tables in mysql
"ftp://myftp.co/ftp/Media_Gallery//Cartoon/Serries/Shaun_The_Sheep/Shaun_The_Sheep_E015.mkv"
now i want remove "//" at the center of my string after "Media_Gallery"
but when i use replace queries // this query remove // at the first of URL and its wrong
my string after run query would be this scheme:
"ftp://ftp.um.ac.ir/ftp/Media_Gallery/Cartoon/Serries/Shaun_The_Sheep/Shaun_The_Sheep_E015.mkv"
UPDATE Mytable SET name = REPLACE(name, 'y//', 'y/');

Incrementing numerical value and changing string in SQL

I have a database that has stored values in a complicated, serialized array where one component is a string and another is the length of the characters of the string, in this format:
s:8:"test.com"
Where "s" holds the character length of the string in the quotations.
I would like to change the string from "test.com" to "testt.com", and I'm using the following statement in SQL:
UPDATE table SET row=(REPLACE (row, 'test.com','testt.com'))
However, this breaks the script in question, because it doesn't update the character length in the "s" preceding the string where "test.com" is stored.
I was wondering if there is a query I can use that would replace the string, and then also increment the value of this "s" preceding to where the replacement occurs, something like this:
UPDATE table SET row=(REPLACE (row, 's:' number 'test.com','s:' number+1 'testt.com'))
Does anyone know if this kind of query is even possible?
UPDATE table set row = concat('s:',length('testt.com'),':"testt.com"');
If you need to change exact string, then use exact query -
UPDATE table SET row = 's:9:"testt.com"' WHERE row = 's:8:"test.com"';
The string is a "serialized string".
If there are multiple strings to be replaced, it might be easier to create a script to handle this.
In PHP, it goes something like this:
$searchfor = serialize('test.com');
$replaceby = serialize('testt.com');
// strip last semicolon from serialized string
$searchfor = trim($searchfor,';');
$replaceby = trim($replaceby,';');
$query = "UPDATE table SET field = '$replaceby' WHERE field = '$searchfor';";
This way, you can create an exact query string with what you need.
Do fill in the proper code for db connection if necessary.

mysql replace last characters in string if matched

I have a table that has some rogue tags that need replacing
The offending string ends <tr> and needs replacing with </table>
Not all record are affected, so I need to find these and then replace them
Our skills using Update Replace Where are limited as the characters are not unique within the string but their position is, ie the last 4 characters
Have tried using
UPDATE table
SET field
REPLACE (RIGHT(field,4),</table>)
but suspec this is over simplified (and also fails)
try this:
UPDATE table
SET field=concat(left(field,length(field) -4),'</table>')
I had a similar situation in which needed to replace '_' from end of the transaction number field, where there where more than one occurrences of _ in field. Example: 20161124_C_BGN_5570.77_ & 20161121_C_HRK_1502360000__
Solution:
UPDATE temp
SET transaction = LEFT(transaction, LENGTH(transaction) -1)
WHERE RIGHT(transaction, 1) = '_';
// in case of double underscore (__)
UPDATE temp
SET transaction = LEFT(transaction, LENGTH(transaction) -2) # WHERE id = xxx WHERE RIGHT(transaction, 2) = '__';

Mysql cut string, the first character?

Hi is it possible to cut string like this:
String in "data" columns: ,123,456
Cut the first character i.e "," (comma).
So the query is something like:
Update users set data = cut first string...
UPDATE users SET data = SUBSTR(data, 2);
This will iterate through all rows in users and replace data with itself minus the first character.