Solved

Update query question

Posted on 2011-09-26
3
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard 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.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

728 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