Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to subtract data in columns

Posted on 2005-04-26
6
Medium Priority
?
256 Views
Last Modified: 2012-06-21
Hi,

I would like to do the following operation.

Col A- Col B and then put result in Col C.  All the columns are from the same table.

The values are numeric it would be something like this:
Col A - Col B = Col C
    11 - 7      = 4

TIA,
Frank
0
Comment
Question by:fcobuzzi
  • 3
  • 3
6 Comments
 
LVL 28

Expert Comment

by:rafrancisco
ID: 13869817
Try this:

UPDATE YourTable
SET ColC = ColA - ColB
0
 

Author Comment

by:fcobuzzi
ID: 13869865
I have already tried that here is the message that I get, maybe it will help.
 
Invalid operator for data type. Operator equals subtract, type equals varchar.


Frank
0
 
LVL 28

Expert Comment

by:rafrancisco
ID: 13869892
This means that one of your columns (either ColA or ColB) is a varchar.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:fcobuzzi
ID: 13869918
All three columns are varchar.
0
 
LVL 28

Accepted Solution

by:
rafrancisco earned 200 total points
ID: 13869936
OK, try this:

UPDATE YourTable
SET ColC = CAST(ColA AS INT) - CAST(ColB AS INT)
0
 

Author Comment

by:fcobuzzi
ID: 13869992
Thanks for the quick help.
0

Featured Post

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.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
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.
Suggested Courses

575 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