Solved

SQL Query to Compare and then UPDATE

Posted on 2011-02-11
6
213 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
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 40

Accepted Solution

by:
Sharath earned 500 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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 40

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

In this article I will describe the Backup & Restore 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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now