Solved

doubt about update

Posted on 2013-02-06
5
217 Views
Last Modified: 2013-02-08
Hello Guys

How can I do this update

I have a tableA and tableB

Update TableA set valor=tableB.valor, qtde=tableB.Value where TableA.code = 123

I don't know how to go on now

In my tableB I have two fields named:

TableB.prod and TableB.code
both field can be cross with tableA
TableA.prod and TableA.code

I thanks any help
0
Comment
Question by:hidrau
5 Comments
 
LVL 23

Accepted Solution

by:
Ioannis Paraskevopoulos earned 125 total points
ID: 38859421
Hi,

Does this help:

UPDATE	TableA
SET		valor = B.valor,
		qtde = B.Value
FROM	TableA A
		JOIN TableB B
			ON A.prod = B.prod
			AND A.code = B.code

Open in new window


Giannis
0
 
LVL 3

Assisted Solution

by:Nalinkumarbalaji
Nalinkumarbalaji earned 125 total points
ID: 38859423
Select the Below Query - Check and Update the Table. -  I am not using the SQL for Testing this QUERY. This is the sample method. You have to check the TableA and TableB common field and put a join to that field for update.

SELECT

Select  TableA.valor, tableB.valor, TableA.qtde, tableB.Value FROM TABLE A, TABLE B where TableA.code = 123
AND TABLEA.Code=TABLEB.CODE
AND TABLEA.PROD=TABLEB.PROD
Goup by TableA.valor, tableB.valor, TableA.qtde, tableB.Value


Update TableA set valor=tableB.valor, qtde=tableB.Value where TableA.code = 123
AND TABLEA.Code=TABLEB.CODE
AND TABLEA.PROD=TABLEB.PROD
0
 
LVL 11

Assisted Solution

by:David Kroll
David Kroll earned 125 total points
ID: 38859428
update TableA
set value = TableB.valor,
qtde = TableB.value
from TableA
inner join TableB on (TableB.code = TableA.Code) or (TableB.prod = TableA.prod)
where TableA.code = 123
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 125 total points
ID: 38859471
0
 
LVL 1

Author Closing Comment

by:hidrau
ID: 38868707
thanks everybody
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question