?
Solved

SQL Query to Compare and then UPDATE

Posted on 2011-02-11
6
Medium Priority
?
259 Views
Last Modified: 2012-05-11
Hi, I am new to SQL, and would like some help please.

I am trying to compare 2 tables only 1 column in those tables. The tables are

1.) dbo.ImportPCMCost
2.) dbo.ImportIncludedList

The 2 tables are:

1.) dbo.ImportPCMCost.Procedure_Code_ID
2.) dbo.ImportIncludedCost.ID

I want to match these 2 Colums and then I want to UPDATE the FEE Column that is located in dbo.ImportIncludedCost table. Please
0
Comment
Question by:dmanisit
[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
6 Comments
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 34872374
update dbo.importincludedcost
  set fee =?
 from dbo.importincludedcost as c
 inner join dbo.importpcmcost as p
 on c.id=p.procedure_code_id
0
 
LVL 8

Expert Comment

by:rushShah
ID: 34872431
try this,


update c
set c.fee = CASE WHEN c.ID=p.Procedure_Code_ID THEN '?' ELSE '?' END
from dbo.importincludedcost as c, dbo.importpcmcost as p

Open in new window

0
 
LVL 41

Accepted Solution

by:
Sharath earned 2000 total points
ID: 34872821
UPDATE c 
   SET fee = p.fee -- or any hard coded value 
  FROM dbo.importincludedcost AS c 
       INNER JOIN dbo.importpcmcost AS p 
         ON c.id = p.procedure_code_id

Open in new window

0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:dmanisit
ID: 34872865
So I have the Fee in the table ImportPCMCost named Fee that I want to take this Fee and update ImportIncludedList Table Field name Fee also
0
 
LVL 41

Expert Comment

by:Sharath
ID: 34872880
Then try the last statement posted.
0
 

Author Closing Comment

by:dmanisit
ID: 34874512
Thats awesome, thanks.
0

Featured Post

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

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

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

770 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