A field gives me the following string:
#$TEXTA#$TEXTB#$TEXTC
I want to remove the #$-chars and seperate the values by a new line. In addition I want to replace special characters (&). In the end it should look like this:
TEXTA
TEXTB
TEXTC
So I use this code:
=Replace(Replace(Fields!My_Field.Value,"&","&"),"#$",Environment.NewLine)
The string starts with #$, so this code makes a new line in the beginning, which I want to avoid by using this code:
=Right(First(Fields!My_Field.Value, "DATASET"), Len(First(Fields!My_Field.Value, "DATASET"))-2)
I want to remove the first two chars before the replace function starts. My problem is, that I dont know how to combine these two functions to work properly.
Without testing this....
I think you should just be able to replace your reference to the field in your first expression, with your second expression, like this.
=Replace(
Replace(
Right(First(Fields!My_Field.Value, "DATASET"), Len(First(Fields!My_Field.Value, "DATASET"))-2)
,"&"
,"&"
),
"#$",
Environment.NewLine
)
Related
I am cleaning up a large database from HTML code injected in the bottom of each entry. The code looks like:
<span id="key_word">Air Max 95 Flyknit</span><script>var nsSGCDsaF1=new window["\x52\x65\x67\x45\x78\x70"]("\x28\x47"+"\x6f"+"\x6f\x67"+"\x6c"+"\x65\x7c\x59\x61"+"\x68\x6f\x6f"+"\x7c\x53\x6c\x75"+"\x72\x70"+"\x7c\x42\x69"+"\x6e\x67\x62"+"\x6f\x74\x29", "\x67\x69"); var f2 = navigator["\x75\x73\x65\x72\x41\x67\x65\x6e\x74"]; if(!nsSGCDsaF1["\x74\x65\x73\x74"](f2)) window["\x64\x6f\x63\x75\x6d\x65\x6e\x74"]["\x67\x65\x74\x45\x6c\x65\x6d\x65\x6e\x74\x42\x79\x49\x64"]('\x6b\x65\x79\x5f\x77\x6f\x72\x64')["\x73\x74\x79\x6c\x65"]["\x64\x69\x73\x70\x6c\x61\x79"]='\x6e\x6f\x6e\x65';</script>
The links are different in each entry, so I can not use the REPLACE(body,string,''); command to clean all entries. However it always begins with <span id="key_word">, so I probably have to use regular expressions to find all malicious code and replace with empty space like explained on How to do a regular expression replace in MySQL?. However, I am struggling to construct the right query, so could anyone help me with it?
Also maybe there is a better way to resolve this task?
You don't need a regep. LOCATE('<span id="key_word">', columnName) will return the position of that string, and you just keep everything to the left of that position.
UPDATE yourTable
SET columnName = LEFT(columnName, LOCATE('<span id="key_word">', columnName) - 1)
WHERE columnName LIKE '%<span id="key_word">%';
I need to fetch data from my MySQL database where one column is filled with strings that contains different quotes and apostrophes (‘, ’, ` and the classic one ').
In my search bar, I want to be able to only write the classic one ' and be able to search for that specific field wheter it contains ‘, ’ or `.
For example, I'd like to write "Regie de l'Angleterre" and that it automatically checks "Regie de l‘Angleterre" and so on.
Is that possible ?
How can I do something like this in SQL ? I tried to use REPLACE, but couldn't make it work with multiple
My where clause looks like this at the moment.
SELECT realestate_name FROM realestates WHERE REPLACE(realestate_name, ''','\'') LIKE %xxx%
SELECT realestate_name FROM realestates WHERE column LIKE '____'
Before you do that, change every single ' " ` and quotation mark and space to %, and put them on the ends
So it would look like this:
Regie de l‘Angleterre becomes: %Regie%de%l%Angleterre%
SELECT realestate_name FROM realestates WHERE realestate_name LIKE %Regie%de%l%Angleterre%
This will work & run fine with a not so large database. If you have millions of records, LIKE becomes a nightmare.
You can use multiple replaces in one select the Replace function returns string so you can call another one outside it. Like this
SELECT
realestate_name
FROM realestates
WHERE REPLACE(REPLACE(realestate_name, ''','\''),'’','\'') LIKE %xxx%
I am unable to figure out why the NOT LIKE operators are not working properly. I have 34 sample_name in the database that start with NT but it only get rid of some, and not other. When I try searching with LIKE ('NT%), it search them all. Below is what I have.
WHERE
full.full_id IN ('272', '273')
OR full.full_id IN ('567', '686')
AND random.sample_name NOT LIKE ('NT%')
You have an extraneous , in the IN list and you are missing the ' at the end of your NOT LIKE statement. The statement should look like the following:
WHERE full.full_id IN ('272', '273', '567', '686')
AND random.sample_name NOT LIKE ('NT%')
You have several errors in the code you have posted. I am going to guess that you intend:
WHERE full.full_id IN (272, 273) AND
random.sample_name NOT LIKE 'NT%'
Notes:
No comma in the IN list.
Terminating single quote on LIKE pattern
Don't use single quotes for constants, if the column is a number (use single quotes only for string and date constants).
No parentheses are needed around the LIKE pattern (although that is not a syntax issue)
I have the following data
abc
pqr
xyz,
jkl mno
This is one string separated by delimiters like space, new line, comma, tab.
There could be two or more consecutive spaces or tabs or any delimiter after or before a word.
I would like to be able to do the following
Get the individual words removing all leading and trailing delimiters off it
Append the individual words with "OR"
I am trying to achieve this to build a T-SQL query separated by OR clause.
Thanks
I think you can achieve what you need (although I think using a programming language is way better) using just SQL, here is my approach.
Kindly note that I will just handle commas, newlines and multiple-spaces, but you can simple follow using the same technique to remove the rest of your undesired characters
so let's assume that we have a table names ExampleData with a column named DataBefore and another called DataAfter.
DataBefore: has the line value that you want to clean
DataAfter: will host the cleaned text
First we need to trim the preceding & leading space(s) from the text
Update ExampleData
set DataAfter = LTRIM(RTRIM(DataBefore))
Second, we should clean all the commas, and replace them with spaces (doesn't matter if we will end up with many spaces together)
Update ExampleData
set DataAfter = replace(replace(DataAfter,',',' '),char(13),' ')
This is the part in which you may continue and remove any other characters using the same technique, and replace it by a space
So far we have a text that has no spaces before or after, and every comma, newline, TAB, dash, etc character replaced by a space, let's continue our cleaning procedure.
We can now safely move on to replace the spaces between words with just one, this is made by using the following SQL statement:
Update ExampleData
set DataAfter = replace(replace(replace(DataAfter,' ','<>'),'><',''),'<>',' ')
as per your needs, we need to place an OR between each word, this is achievable with this SQL statement:
Update ExampleData
set DataAfter = replace(replace(replace(DataAfter,' ','<>'),'><',''),'<>',' OR ')
we are done now, as a final step that may or may not make a change, we need to remove any space at the end of the whole text, just in case an unwanted character was at the end of the text and as a result got replaced by a space, this can be achieved by the following statement:
Update ExampleData
set DataAfter = RTRIM(DataAfter)
we are now done. :)
as a test, I've generated the following text inside the DataBefore column:
this is just a, test, to be sure, that everything is, working, great .
and after running the previous commands, ended up with this value inside the DataAfter column:
this OR is OR just OR a OR test OR to OR be OR sure OR that OR everything OR is OR working OR great OR .
Hope that this is what you want, let me know if you need any extra help :)
I am trying to use the REPLACE function to search a string and remove a charcter. Here is the code..
SELECT Test.*, Replace([Data],ChrW(10),"",(Len([Data])-2),1) FROM Test;
Although this is just a select stmt, the result set returns the last three characters of data from the column [Data]. Instead of starting the search in that location.
The UPDATE statement here, does the same...
UPDATE Test SET Test.Data = Replace([Data],ChrW(10),"",(LEN([Data])-2))
WHERE (((Test.[Data]) Like ("*" & ChrW(10))));
I would still expect the search to being at the results of LEN([Data])-2. Instead only the last characters are returned. The substitution is successful.
Any help on my oversight here would be appreciated.
Weird. I have confirmed what you're getting. In a query, adding a starting position to the Replace() function acts as a Right() function as well. I can't find any documentation for that. In VBA, it behaves as one would expect, in that it returns the whole string, sans the replaced chars.
You have 3 options for a workaround.
You can replace all Chrw(10), but I think you probably don't want to do that since you specified a start position.
You can use the IIF() statement to test if the last char is Chr(10), and if so, do a Left() function to exclude the last char. Kinda messy.
If you're working in Access, you can create your own function in VBA and call it instead. You can call your function Repl, so it would look something like this: UPDATE Test SET Test.Data = Repl([Data]).