Transfering data between one data base to another in SQL - mysql

I am trying to transfer a couple of columns from an old database to a live database.. The issue I have is that I need the columns to match up with a column on the live database. For instance let me use an example: My live database has a table like this
TABLE NAME is ITEMS Then inside the table there would be a columns name ItemLookUp and ExtensionDescription.
So the live table would look something like this:
**ItemLookUp** **ExtensionDesctiption**
AAA-06-201 'Blank'
BBB-08-201 'Blank'
CCC-99-201 'Blank'
The old database would look like this:
**ItemLookUp** **ExtensionDescription**
AAA-06-201 Toy part
BBB-08-201 Mechanic Part
CCC-99-201 2x1 Screw
So what I am trying to do is make the live database have the information of the old database, but the ExtensionDescription needs to match up with the ItemLookup meaning for example if the ItemLookUp is AAA-06-201 it must have an ExtensionDescription of Toy part... Any help would be greatly appreciated.

Try on this. I thik this will help you.
update tbnew
set tbnew.ExtensionDesctiption = tbold.ExtensionDesctiption
from tbold
where
tbnew.ItemLookUp = tbold.ItemLookUp

UPDATE dbnew.items a JOIN dbold.items b
ON a.ItemLookUp=b.ItemLookUp
SET a.ExtensionDescription=b.ExtensionDescription
Assuming same server.

Figure it out.. Thanks for all your help
update Item
set ExtendedDescription = X.ExtendedDescription
from Item I
INNER JOIN /old db name/raxx.dbo.Item X on I.ItemLookupCode = X.ItemLookupCode
WHERE I.ItemLookupCode = X.ItemLookupCode AND I.ExtendedDescription like ''

Related

How to select database with dot in its name with laravel?

i have a project to show database value...
but, the database name has dot in it.
my database name is "t.produk".
How can i select the database in laravel?
i run it and got an error says it invalid like below
EDIT:
and i also did it with just string, came out error too :
Here the picture
First of all - avoid naming database tables like that. You should not use any dots there. It could be t_produk as example.
But table name should be descriptive so go for something like products. Than name your entity as Product.
You get this error here because you can't set variable as (t.produk). You should pass a string as I see here. So do it like this:
protected $table = 't.produk';
EDIT:
I saw the error with a string variable. So now you see why the current table naming you choose is quite not good. DB reads it as follows:
select from database t table produk
If you will name your table like t_produk problem should be no longer here.
My bad, so the tables name can't have dot in it. noted.
Btw y'all thanks for the answers :)

how to delete single record from list

I have a record in table column like this (1001,1002,1003,1004,1005)
and I want to delete "1003" from this list. Please help me.
For your own good, don't store data like this. This type of issue is not, by far, the biggest problem you will run into.
This being said, you can solve you issue by using:
UPDATE TABLE
SET COLUMN = REPLACE (COLUMN, ',1003,', ',')
WHERE ID = PK;
even this will work:
update tablename set column=(select
substr(column,1,instr(colname,',',2))||susbtr(column,instr(column,',',3),length(column)-
instr(column,',',3)) from tablename where id=value;

MySql, Copy one column into another and add some text

I have a column which has an Article-ID and one empty with the picture filename. Example: The article with the ID 34.67 should get the filename 34.67.jpg and so on. There are about 20'000 articles.
What would be the best way to do this?
Depending on your table structure or SQL dialect - it will be something like this:
UPDATE Tablename SET filename=concat(articleid, '.jpg')
OK, Thank you very much. I ended up using following code. This worked like a charm.
UPDATE oxarticles SET OXPIC1=LOWER(concat(OXARTNUM, '.jpg')) WHERE OXPIC1 = ' '

MYSQL - two tables in different databases

I need to check phone number to see if they match but the issue is, that one table is in database A and another is in database B.
I am wondering is there away to do a search like this:
update `chk_dup`, new set chk_dup.dup='Y' WHERE chk_dup.phone = new.phone;
But I guess I would need to do something like this:
update `A.chk_dup`, B.new set A.chk_dup.dup='Y' WHERE A.chk_dup.phone = B.new.phone;
I any one knows how to search two tables in completely different databases that would help.
I think in your second one you had a syntax error, try this one:
UPDATE `A`.`chk_dup`, `B`.`new`
SET `A`.`chk_dup`.`dup`='Y'
WHERE `A`.`chk_dup`.`phone` = `B`.`new`.`phone`;

Duplicate column and add an automatic extension with mySQL. How?

I have two columns with mySQL:
"part_no"
"pdf_link"
I need the "pdf_link" column to automatically grab/duplicate the "part_no" value and add a .pdf extension on the end.
For example: If part_no = 00-12345-998, then pdf_link = 00-12345-998.pdf
I need this to happen every time I insert.
I appreciate the help.
Erik
you can achive this effect by using triggers I think.
http://dev.mysql.com/doc/refman/5.0/en/trigger-syntax.html
CREATE TRIGGER ins_pdf AFTER INSERT ON MY_TABLE SET #pdf_link = concat(#part_no,'.pdf')
Why store this extra computed information in the database? You can do this in the query when you pull it out, or, if needed, you could make a view that does it only as-needed.
Example pseudo query (my brain hurts right now, so this is only an example):
select concat(`part_no`, ".pdf") as `pdf_link` from `parts`;
If you really need this, you could use a trigger to duplicate the data ans add the extra string.