Fellow overflowers,
I am working with a database to sort several other databases and change some values so my scada application can use the values in the database.
Now I have encountered the following problem:
I have a column called "Name" and in this column are string values like this one:
S1\SVS_AK\STS\Status[7]
From this string I'd like to cut (or copy, doesn't really make a difference eitherway) the "[7]" part and paste this behind whatever I have in a different column.
So for example:
I have a column "Address" and a column "Name"
I want to take the [7] from the Name Column and paste that behind the already existing string "DB32,7.3" wich exists in the column Address
How can I possibly do this? Preferably with a query
Thanks in advance!
How about:
UPDATE ATable SET AField2 = Mid(AField,instr(AField,"[")) & AField2
You might like to add
WHERE AField Like "*[[]*"
[ is a special character, so it need to be bracketed for the Like statement, as illustrated.
Related
Maybe that stupid question, but I don't know how to describe my problem to uncle google.
I have two simple tables with 3 rows: ID, Name, SomeVal;
Now I want update them with merge, and that's simple:
MERGE Locations T
USING Locations_2 S ON T.ID=S.ID
WHEN MATCHED THEN
UPDATE
SET
T.Name=S.Name,
T.SomeVal=S.SomeVal;
Ok, that works, but I wrote every column name by hand. So, when I want to update for example table with 30 columns, writing everything by hand will be painful. So, is there any option to update every column in the table no matter how many columns it has?
I tried "*". It is UPDATE SET T.*=S.*, and that didn't work.
What I normally do when I want to be time efficient (or lazy, depending on your view) is this:
Run this command:
sp_help TableName;
Copy/paste the first column, then hold down Alt whilst dragging the mouse cursor in front of the column names. This way I can then type one comma in front of all the fields. Then I do the same after the field name except with an = sign.
That's the only shortcut I can think to help you, and has saved me hours of typing over the years.
No. Merge statements are very verbose. You can hack a shortcut by scripting your table as CREATE, copy the column names using SHIFT + ALT to select a large swath of them, then paste them into the MERGE query, hit space, add the = sign, then paste again.
The statement is one direction, (i.e., you can't update S with T; only T can be updated) so you don't strictly need to provide the source/destination alias for each column.
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.
I am new to PostgreSQL and am attempting to create a query that will clean up certain columns within a table. By "clean up" I mean delete all characters before or after a certain symbol.
I have one column called "Campaign" within a table called "Adwords".The column has this string/structure within all rows, DE-SRC-Brand. The only place that I would like to keep in this column would be where Brand currently is. I had previously done this manually through excel by doing a simple search and replace with "*-" as the searching criteria.
How would this formula translate to PostgreSQL? How would it then also change if I would like to delete characters in front of a certain designated symbol. Please let me know if anything is unclear as I am still new to this program.
If you want to extract the brand, you can use substring() with a pattern:
select substring(campaign from '%-%-#"%#"' for '#') as brand
from adwords;
You can incorporate this into an update:
update adwords
set campaign = substring(campaign from '%-%-#"%#"' for '#')
where campaign like '%-%-%';
I have a table called tabTranslations and I need to find all occurrences of a word and change it to something else(whilst preserving any other words in the record). Is this possible without changing every record manually? As this would take me forever.
For example let's say I wanted to find the word "value" in all the records and change it to "values", but there may be a record with the text "some text value" in which case I would want it to then read "some text values".
I only really know the very basics of SQL so I'm unsure if I can do this or how I would go about it.
This query should work.
update tabTranslations
set columnName = REPLACE(columnName,'value','values')
I want to delete a certain string in a cell in MS Access, whether in a column or in the whole table. I know that I can do this using plain old Find and Replace but in this case it is not economical for my thousand-row table.
For example,
remove all Unknown values from all columns.
remove the string "dollars" from the values in column price ie. if the cell contains "34 dollars", it will just be "34".
Can this be done in SQL and how?
Assuming your query will run within an Access session, the second goal is easy. You can Replace dollars with a zero-length string.
UPDATE YourTable
SET price = Replace(price, 'dollars', '');
You could use the same strategy for the first goal, but may decide it makes more sense to examine the datatypes of the table's fields and only UPDATE those which are text or memo.