Format text substring differently from the remaining text in DataStudio/Looker? - html

I am new to looker/ datastudio, and trying to highlight/bold/italic part of a string, in a text field of a table.
For example, here's a table I created on Looker DataStudio, I want specific words in Col3 to be highlighted in the report.
Col1
Col2
Col3
1
2
Hello World
55
39
Marry had a little lamb
What could be the best way to approach this problem?
I also tried using '< b >', '< /b >' HTML tags but the field itself can be only either TEXT or NUM not HTML.

Related

MySQL strip ' on where queries

I have a large table which contains, or not, records that have ' tags like (martin's, lay's, martins, lays, so on).
Actually to search the client can be write exactly text, for example: martin's, to search all records that contains "martin's" but it is complicate, then, I need the client can to search by "martins" or "martin's".
This is a simple example:
A mysql table like:
ID | Title
---------------
1 lays
2 lay's
3 some text
4 other text
5 martin's
I need a sql query to search by lays or lay's and both need show me a Result like:
ID | Title
---------------
1 lays
2 lay's
I'm tried with many post solutions but I cant do that :-(
Appreciate any help.
Just remove the single quote:
select t.*
from t
where replace(t.title, '''', '') = 'lays';
To search if the word contains:
select t.*
from t
where replace(t.title, '''', '') LIKE '%lays%';

Get rows that contain less than 4 digits only

I need to fetch the rows that contain less than 4 consecutive digits. I tried using this :
select mycolumn where mycolumn REGEXP '[0-9]{1,3}'
but this still returned rows such as
"Test Text 1234-1234"
I need to return these only:
Test 12
Test 234 Text
Test /2 Text
text 123 text 1234 text
Thanks to #BenM and #lad2025, the correct answer is:
'[[:<:]][0-9]{1,3}[[:>:]]'
http://sqlfiddle.com/#!9/af95e/3/0

update single varchar field in table from several of same type in other database and table and combine with line breaks

If my answer is in another post, I've not found it. A post I thought might have my answer was
"I want to concatenate 2 strings from 2 textareas and insert them into a column in my table."
I am converting some data. Other database has text that is stored in the same table, different fields. each field (x.description_plain_text has a sequence number as illustrated in the script. As you can maybe see with my attempt, I would like to bring both of the text lines into one (varchar(8000)) field and separate with a line or two. I don't know if I am allowed to tag a second objective, but if/after I get these separate lines from the other database into one field in my new database I then want to be able to put an identifier next to each ... as I am trying to show in the 2nd illustration ...
1st illustration
--select x.description_plain_text, x.SEQ_NO
update MIC.dbo.Item set CustomerDocumentNote =
case
when x.SEQ_NO = 1 then cast(x.description_plain_text as varchar(8000))
when x.SEQ_NO = 2 then cast(x.description_plain_text as varchar(8000))
END
-- x.description_plain_text + CHAR(13) + CHAR(10) + cast(x.description_plain_text as varchar (8000))
from MIC.dbo.Item a
inner join in_item_xdesc x on x.item_id = a.itemid
where (a.ItemNumber = '14661')--(IS_PRINT_ACKNOW = 'Y' and SEQ_NO = 2)
2nd illustration ... need a SQL query that will give me just the description with P_A ... P_A is merely an identifier ... can be anything ... just a way to say If P_A then print but IF
P_PT_PO THEN print ...
P_A - Heater with 1.5" OD flange at 2.5", 48" mica leads with 36" SS braid exiting 90° from sheath, single clip support. 800 Watts & 240 Volts. For Gala pellitizer.
+ CHAR(13) +
P_PT_PO - Stamp "MIC #14661" on OD of heater. Silicone over Cement at lead ends.

mysql replace string + next one char

Is it possible to REPLACE a string + next character in MySQL? Something like LIKE underscore.
For example, if text column is this:
12 13 14 14_B 15 14_A, REPLACE all 14_* with an empty character, and replaced text should be:
12 13 14 15
You'll be looking to do this using a regular expression UDF in MySQL. Key ingredients are
regular expression UDF - check here
The regular expression itself
If you will ONLY ever see 2 to 4 of these that you need replaced, a poor man's working approach (SQL Fiddle):
SELECT *,IF(LOCATE('14_',B)+3<=Length(B),
INSERT(B,LOCATE('14_',B),4,''),B) C
FROM
(
SELECT *,IF(LOCATE('14_',A)+3<=Length(A),
INSERT(A,LOCATE('14_',A),4,''),A) B
FROM (
SELECT *,IF(LOCATE('14_',x)+3<=Length(X),
INSERT(X,LOCATE('14_',x),4,''),X) A
FROM X
) Q1
) Q2
I've only catered for 3 replacements but you can easily expand the pattern. Include only the columns from the base table needed in the outermost query.

sql query to fetch tag information from single table

I have a table (Mysql) with different snippets with tags in a coloumns
table snippets
---------------
Id title source tag
1 "title" "srouce code" "Zend, Smarty"
2 "title2" "srouce code2" "Zend jquery"
3 "title3" "srouce code3" "doctrine"
I want to do a select statements so that I can build a tag clouds on my site.
Zend(2), smarty(1), jquery(1), doctrine(1)
Remember tages are not always sperated by space, some tages are separated by comma(,)
then I need a query to fetch all records with specific tages. which I think i can use something like that untill there is better solution for that.
Select * from snippets where tag like "%ZEND%"
looking for optimized solutions please.
create three tables!
table snippets
id | title | source_code
1 "title" "srouce code"
2 "title2" "srouce code2"
3 "title3" "srouce code3"
table tags
id | tag
1 "zend"
2 "smarty"
3 "doctrine"
4 "jquery"
table snippets_tags
id | snippet_id | tag_id
1 1 1
2 1 2
3 2 1
4 2 4
5 3 3
Tip: lower-case your tags because "Zend" and "zend" are the same
Now your tag cloud query should look like
SELECT tags.name, COUNT(snippets_tags.id) AS snippet_count
FROM tags LEFT JOIN snippets_tags ON snippets_tags.tag_id = tags.id
GROUP BY tags.id
Gives you a result like
name | snippet_count
zend 2
smarty 1
doctrine 1
jquery 1
To select all snippets belonging to a certain tag:
SELECT snippets.* FROM snippets, tags, snippets_tags
WHERE
snippets_tags.snippets_id = snippet.id AND
snippets_tags.tag_id = tags.id AND
tags.name LIKE '%zend%'
Have you thought about separating the source code and tags into separate tables?
Source Table
ID, Title, Source
1 "t1" "sc"
2 "t2" "sc"
3 "t3" "sc"
Tag Table
ID, Tag
1 "Zend"
2 "Smarty"
3 "jquery"
4 "doctrine"
SourceTagLink Table
SourceID, TagID
1 1
1 2
2 1
2 3
3 4
That way you have a unique list of tags that you can choose from, or add to.
You wont be doing any string parsing so your selects will be much faster. Sort of similar to how you assign tags to your post on this site.
EDIT
This is a function that I used to convert a multivalue string into a table with a single column it written is MSSQL but you should be able to convert it to mySQL
CREATE FUNCTION [dbo].[ParseString](#String NVARCHAR(4000), #Delimiter CHAR(1)=',')
RETURNS #Result TABLE(tokens NVARCHAR(4000))
AS
BEGIN
-- We will be seearching for the index of each occurrence of the given
-- delimiter in the string provided, and will be extracting the characters
-- between them as tokens.
DECLARE #delimiterIndex INT
DECLARE #token NVARCHAR(4000)
-- Try to find the first delimiter, and continue until no more can be found.
SET #delimiterIndex = CHARINDEX(#Delimiter, #String)
WHILE (#delimiterIndex > 0)
BEGIN
-- We have found a delimiter, so extract the text to the left of it
-- as a token, and insert it into the resulting table.
SET #token = LEFT(#String, #delimiterIndex-1)
INSERT INTO #Result(tokens) VALUES (LTRIM(RTRIM(#token)))
-- Chop the extracted token and this delimiter from our search string,
-- and look for the next delimiter.
SET #String = RIGHT(#String, LEN(#String)-#delimiterIndex)
SET #delimiterIndex = CHARINDEX(#Delimiter, #String)
END
-- We have no more delimiters, so place the remainder of the string
-- into the result as our last token.
SET #token = #String
INSERT INTO #Result(tokens) VALUES (LTRIM(RTRIM(#token)))
RETURN
END
Basically you call it like
ParseString('this be a test', ' ')
it will return a single column table
this
be
a
test
ParseString('this:be a test', ':')
returns
this
be a test
You could add a call to the function in an update trigger to populate the new tables to help you make selects much easier. Once the trigger is built, just do a simple update like the following
Update yourTable
Set Title = Title
That fill fire the trigger and populate the new tables and make everything much easier for you without affecting existing code. Of course youll need to replace all known delimeters with a single one for it to work.
Any new records added or modified will automatically fire the trigger.
At first you have to replace all characters like ',' space etc. with a fixed "separator" character like '#'. You could use a temporary table.
Then you have to create a function that loops over the fields and searches and counts the single tags.