Solved

Update query question

Posted on 2011-09-26
3
229 Views
Last Modified: 2012-05-12
I have to Update 3 fields in the Nop_ProductVariant table
with the values from the "ProdOne" table, based on the SKU field which is nvarchar(100).
Being the SKU is not an "int" field, what it the best way to do the join?

UPDATE Nop_ProductVariant
SET   OldPrice =   , ProductCost =  , Downloads =  

INNER JOIN ??
WHERE ???      SKU =

SELECT SRP, Cost, DL
FROM ProdOne

0
Comment
Question by:MikeMCSD
3 Comments
 
LVL 19

Accepted Solution

by:
Bhavesh Shah earned 500 total points
ID: 36599958

UPDATE A
SET   OldPrice =   SRP, 
ProductCost =  Cost, 
Downloads =  DL
FROM Nop_ProductVariant A INNER JOIN ProdOne B
ON A.SKU = B.SKU

Open in new window


0
 
LVL 16

Author Comment

by:MikeMCSD
ID: 36600155
perfect, thanks
0
 
LVL 1

Expert Comment

by:szefcyk
ID: 36600352
I'm assuming SKU is in both the Nop_ProductVariant and ProdOne tables....so you could try this...

DECLARE @OldPrice varchar(30)
DECLARE @ProductCost varchar(30)
DECLARE @Downloads int
DECLARE @SKU int
DECLARE @dynSQL nvarchar(1024)

SET @SKU = 1234
SELECT @OldPrice = SRP FROM ProdOne WHERE SKU = @SKU
SELECT @ProductCost = Cost FROM ProdOne WHERE SKU = @SKU
SELECT @Downloads =  DL FROM ProdOne WHERE SKU = @SKU

SET @dynSQL = 'UPDATE Nop_ProductVariant SET OldPrice = ' + @OldPrice + ', '+
	'ProductCost = ' + @ProductCost + ', Downloads = ' + CAST(@Downloads AS varchar) +
	' WHERE SKU = ' + CAST(@SKU AS varchar)

--PRINT @dynSQL
EXEC sp_executesql @dynSQL

Open in new window

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now