SQL mass replace column value [duplicate] - mysql

This question already has answers here:
MySQL string replace
(6 answers)
Closed 8 years ago.
I have a database with a table name called mybb_users.
All users have a field name called avatar. Some users have their avatar set as
http://graph.facebook.com/userid/picture?width=250&height=250.
I want to mass-replace all the width and height of the people that use a facebook picture with this amount of width and height. I unfortunately don't know how to do this since the userid is random. Is there anyway I can mass replace width=250&height=250 to width=140&height=140 ?
Thank you!

you can do it with the REPLACE function:
UPDATE mybb_users
SET avatar = REPLACE(`avatar`, 'width=250&height=250', 'width=140&height=140')
WHERE avatar like '%graph.facebook%'
for further information have a look at: http://dev.mysql.com/doc/refman/5.6/en/string-functions.html#function_replace

You can update just the portion you want like this:
UPDATE mybb_users SET avatar = REPLACE(avatar, 'width=250&height=250', 'width=140&height=140')
this should replace all occurences of the 250 with 140

Related

Report with combined fields

I need to create report to render like image below:
So, for each question, I have several answers (4 or 5 answers), and every question have belonging image.
DATASET:
QuestionId QuestionName Image AnswerId AnswerText
1 Question 1 Image 1 Answer 11
1 Question 1 Image 1 Answer 12
1 Question 1 Image 1 Answer 13
1 Question 2 Image 1 Answer 21
1 Question 2 Image 1 Answer 22
1 Question 2 Image 1 Answer 23
1 Question 3 Image 1 Answer 31
1 Question 3 Image 1 Answer 32
1 Question 3 Image 1 Answer 33
To do this I have made the following assumption
You want each Question Text to appear as a new question with it's own associated answers
I would implement this using a List in SSRS
Add a new List item, and set it's DataSetName to your Dataset. (I have also set the BorderStyle to Solid in the example below)
Right click the Row Header, and select Row Group -> Group Properties, then Group on QuestionName
Within the body of the list item, draw a textbox for the Question name, and Create a Placeholder in it with the value =Fields!QuestionName.Value
Add a new image box, and set it to use the image =Fields!Image.Value
Finally add a new table, and set the data to be =Fields!AnswerText.Value. (You may also want to remove the header row)
The final layout should be something like this
And when run will render as
Hopefully this is the sort of thing you are after. If not then let us know to provide further assistance.

How to add an image in my database table

I got a table with columns but i'm trying to update the 'img' column to a specific image.
This is what I tried :
UPDATE employees
SET img="(LOAD_FILE('C:/Users/Test/Desktop/Test.png')"
WHERE wname='Foo';
Sadly enough the picture doesn't get converted to a real image.
You are using LOAD_FILE in wrong manner, Try this :
UPDATE employees
SET img=LOAD_FILE('C:/Users/Test/Desktop/Test.png')
WHERE wname='Foo';
See detail : http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_load-file
In you query you are just setting the value of img as
"(LOAD_FILE('C:/Users/Test/Desktop/Test.png')" because of the double coats.
So instead of file being uploaded path location is being inserted
"(LOAD_FILE('C:/Users/Test/Desktop/Test.png')"
#Sagar Joon is absolutely right you have do the way he is saying.

SSRS - Column Group - Table Horizontally Expanded

There was a requirement, to have data horizontally expanded in the Rows. So I have created Child Row group in Column group of Matrix as shown in this link.
Reference Link
It is working fine. And it displays result as below.
Requirement was : Show Thumbnails of images uploaded for a building as above.
But now the problem is, when there will be number of images, this is going to be expanded horizontally.
I want to repeat this Row after 8 or 10 images.
Any Idea how can I achieve this in SSRS ?
Thank you,
Mittal.
Not quite sure about your requirement, do you want those images wrap in your report, each row has maximum 8 images? If so, we need to make each 8 images into one group. In this scenario, we can create a list. If you have a index field (like a specific id for each image) in your dataset, we can put in the group expression with this:
=ceiling(Fields!Index.Value/8)
If you don't have this kind of index column, we can make it manually. Embed the custom code below:
Dim CountNumber As Integer = 0
Public Shared Previous as Object
Public Function GroupNumber(ByVal category As Object) As Integer
If Category <> Previous then
CountNumber = CountNumber + 1
Return CountNumber
Else
Return CountNumber
End If
End Function
Then replace the group expression with this:
=ceiling(Code.GroupNumber(Fields!Image.Value)/8)
I have tested in my local environment and it works. But I can't share the screenshot due to low reputation.

Only allow certain user input in html form

I am trying to allow only certain data to be inserted into an html form field...
i currently have
pattern="[A-za-z]{2}[0-9]{6}"
which works great for a reference number starting with RQ and then 6 numbers.
how can i add another pattern to allow 3 letters with 8 numbers after that?
for example INM12345678
so that users can only use RQ123456 or INM12345678
try this:
/(RQ\d{6}|INM\d{8})/
here is the demo see here
If you want to limit valid data as said in comment:
^RQ[0-9]{6}|INM[0-9]{8}$

MySQL Replace query

I have one table, and I need to remove a specific text from a specific field. This field contains a full URL of an image, I need to remove the URL and just keep the image filename.
So:
Current date: fieldname: www.example.com/photo.jpg
What I want to do is remove www.example.com/ from all of the entries for this field.
I know how to use the search and replace function, but I don't know how to leave part of the data intact.
This is what I've used but can't modify it to make it work the way I want:
UPDATE table SET oc_upload1 = REPLACE(oc_upload1,'newtext') WHERE oc_upload1 LIKE "oldtext"
Is this possible? If so, how? Thank you!
This should do:
UPDATE table
SET image = REPLACE(image, 'www.example.com/','')
but, it's possible that image contains 'www.example.com/' as part of image file name so to be extra safe and replace only the first occurence of www.example.com
UPDATE table
SET image = SUBSTRING(image, LENGTH('www.example.com/') + 1)
WHERE image LIKE 'www.example.com/%'
But if You really, really just want the file name and not path to the file You can also use:
UPDATE table
SET image = SUBSTRING_INDEX(image,'/',-1)
Note that above statement will change 'www.example.com/images/01/02/daisy.jpg' to 'daisy.jpg', not 'images/01/02/daisy.jpg'. It also wont change rows that does not contain '/' in image.