Solved

Update query question

Posted on 2011-09-26
3
233 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

738 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