Advertisement

07.24.2008 at 03:47PM PDT, ID: 23594076
[x]
Attachment Details

UPDATE statement help

Asked by k3n51mm in .NET, MS SQL Server, .Net Editors & IDEs

Tags: SQL

I have two tables in a dataset. One of the tables has an empty column I'm trying to fill based on field matching in another table in the dataset. We're not yet able to use LINQ (Framework 2.0), but we are using a very good 3rd-party component called QueryADataset that enables standard SQL queries for in-memory datatables. I trust the component more than my rather rusty SQL skills.

I have the following query that gives the error: The column prefix 'Table1' does not match with a table name used in the query.'

UPDATE Table1
SET Field1 = (SELECT Field1 FROM Table2
WHERE
(Table1.Field2 = Table2.Field2
AND
Table1.Field3 = Table2.Field3))

Given that Table2.Field1 contains the value I need to store in Table1.Field1, and that I can find it by matching Fields 2 and 3, how should I rewrite this query to work correctly? I guess it should be some kind of join, but it's not coming to mind.

ThanksStart Free Trial
[+][-]07.24.2008 at 04:07PM PDT, ID: 22084498

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 04:33PM PDT, ID: 22084692

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .NET, MS SQL Server, .Net Editors & IDEs
Tags: SQL
Sign Up Now!
Solution Provided By: emoreau
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.24.2008 at 05:36PM PDT, ID: 22085053

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628