Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Update query question

Posted on 2011-09-26
3
Medium Priority
?
237 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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
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.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

610 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