how to change specific text in a column but keep the rest - sql

I am using SQL in navicat. I would like to change the UID below to id and keep the rest of the text in each column. The numbers after the = are different in each record.
EXAMPLE:
3PYTW2X?UID=5493139 and I want it changed to 3PYTW2X?id=5493139
3PYTW2X?UID=2986225 and I want it changed to 3PYTW2X?id=2986225
I have about 200k records that need to be updated.
Thank you in advance!

Use a replace function:
REPLACE(FieldName,'UID','ID')

Related

How to update a sql record text, by replacing a string for various text?

I have to update a table record where I am replacing some old email ids with a new id.
I am at the moment doing replace like
replace(replace(replace( column, 'abd#xyz.com', 'new#email.com),'old#re.com', 'new#email.com'),'asda#sdfsd.f', 'new#email.com')
Is there any simple way to do it?
I am not sure why a column would contain an email and other information. So perhaps this does what you want:
update t
set column = 'new#email.com'
where column in ('abd#xyz.com', 'old#re.com', 'asda#sdfsd.f');
If the column contains additional information, I would recommend that you fix your data model rather than trying to make a broken data model work.

Postgres - split number and letter doesnt fill column

I have received help for splitting a column wit nr and letter.
In the SQL script it all works perfect. It runs complete, with no errors.
But the columns itself doesn't get filled.
I have tried to create te columns in advance as text or as integer. But it doesn't get filled. The SQL query it self turn out ok. But in reality it stay empty. What is wrong?
Your question is not completely clear, but it sounds like what you are trying to do is take a value from one column of a table, split it and use the result to update two other columns in the same table.
If that is the case, you would want to be using the SQL UPDATE command instead of SELECT.
UPDATE d1_plz_whatever
SET nr=SUBSTRING(hn FROM '^[0-9]+'),
zusatz =SUBSTRING(hn FROM '[a-zA-Z]+$');

Want to find fields in a column that start with certain letters

I'm looking to find a way fields that only start with certain letters
Example: Within the "Postcode" column on the report, I want to show only postcodes that start with "CF"
My best guess would be to create an object that marks these down as a number, but I don't know how to identify them.
Thanks for any advice.
In the case of Webi.
You can create variable, wich helds only symbols you are interested in. In your example it would be:
f=left([Postcode];2)
Then restrict table in the report by filter. And add values you want to filter list.

How do I create a Identity starting with a Letter first then numbers after?

I want to create data that contains info about my supplier making it auto generate his ID.
For example, SupplierID I want it to appear as - SID001, SID002 all to auto generate after each other.
How do I do this with SQL?
Ask yourself this: what are the costs of doing this? In particular, what is required to compare two strings versus comparing two numbers? To generate strings from numbers?
Then ask yourself, what value is added by having an id of 'SID0001' rather than just 001?
Then ask yourself, is there an easy way to display a prefix without redundantly storing it for each row? (Answer: yes, with a database view).
You could just use a sequence or identity column and store the prefix in a separate column, or alternately, if the table in question will only ever have suppliers with a prefix of SID, don't store the SID part at all and simply add it at the application level.
You could check for the next ID available and concatenate your prefix with that value. The result should be inserted in the SupplierID column.
Some databases(Oracle, postgres etc) support a sequence for number part. Some(mysql) have an auto increment feature, so you get new number when inserting.
You could then concatenate with string to generate string based IDs.

query a table not in normal 3rd form

Hi I have a table which was designed by a lazy developer who did not created it in 3rd normal form. He saved the arrays in the table instead of using MM relation . And the application is running so I can not change the database schema.
I need to query the table like this:
SELECT * FROM myTable
WHERE usergroup = 20
where usergroup field contains data like this : 17,19,20 or it could be also only 20 or only 19.
I could search with like:
SELECT * FROM myTable
WHERE usergroup LIKE 20
but in this case it would match also for field which contain 200 e.g.
Anybody any idea?
thanx
Fix the bad database design.
A short-term fix is to add a related table for the correct structure. Add a trigger to parse the info in the old field to the related table on insert and update. Then write a script to [parse out existing data. Now you can porperly query but you haven't broken any of the old code. THen you can search for the old code and fix. Once you have done that then just change how code is inserted or udated inthe orginal table to add the new table and drop the old column.
Write a table-valued user-defined function (UDF in SQL Server, I am sure it will have a different name in other RDBMS) to parse the values of the column containing the list which is stored as a string. For each item in the comma-delimited list, your function should return a row in the table result. When you are using a query like this, query against the results returned from the UDF.
Write a function to convert a comma delimited list to a table. Should be pretty simple. Then you can use IN().