Solved

SQL Query to Compare and then UPDATE

Posted on 2011-02-11
6
242 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
Error in SSIS while executing  - Potential data loss 4 31
Webservices in T-SQL 3 34
Query Syntax 17 43
Clone table from one server.database to another server.database 24 37
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

830 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