Q

# Doing SQL arithmetic with SELECT instead of arithmetic operations

## Learn how to do simple SQL arithmetic operations without using the arithmetic operators.

I have a small question about SQL arithmetic to ask. I have an employee table that includes two columns: employee...

number and salary. Example:

EMP      SALARY
1            10
2            20
3            30

I have to craft a query to print all rows of the employee table after multiplying the numbers in the salary column by 100. But I can only use a SELECT statement, not any SQL arithmetic operations. So the output should be:

EMP      SALARY
1            1000
2            2000
3            3000

#### More on SQL arithmetic and other SQL questions

First, I just have to say this question makes me wonder about its purpose. I can't imagine why SQL arithmetic operations couldn't be used in a real-life situation. Anyway, I can easily answer the question, given a couple of assumptions:

1. Salaries are always stored in the table as multiples of 100.
2. Salaries are always numeric or null; or if they are non-numeric, the final display answer still makes sense ending in 00.

`SELECT emp, to_char(salary) || '00' as salary`

`FROM employee;`

Since this is a concatenation operation, not an arithmetic operation, the answer meets your limiting criteria and provides the answer you want.

This was last published in February 2013

## Content

Find more PRO+ content and other member only offers, here.

#### Have a question for an expert?

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

#### Join the conversation

Send me notifications when other members comment.
I think this technique is dangerous in long run. Generally developers don't remember their code for long time and that makes the difference. This little piece of code can't be used as a sub-query where the mathematics does not end there. If we remember the rule 'GARBAGE-IN and GARBAGE-OUT', this query would produce wrong result when the salary has NULL or decimal values. So we need to be very careful while using this technique. Well this is only my opinion and not a part of any print.

-Hara
Cancel
I think this technique is dangerous in long run. Generally developers don't remember their code for long time and that makes the difference. This little piece of code can't be used as a sub-query where the mathematics does not end there. If we remember the rule 'GARBAGE-IN and GARBAGE-OUT', this query would produce wrong result when the salary has NULL or decimal values. So we need to be very careful while using this technique. Well this is only my opinion and not a part of any print.

-Hara
Cancel
1) resulting datetype
2) nls parameters
Cancel
"First, I just have to say this question makes me wonder about its purpose. I can't imagine why SQL arithmetic operations couldn't be used in a real-life situation."

Cancel
It is amazing how consistent is Karen in getting simple sings wrong. First, SQL arithmethic (well, actually, math, since there is a full set of functions available) is quite a routine and very useful application of SQL. Second, for many reasons (but you need to know what NULL is to discuss them) the answer is "*100", not "||'00'".
Cancel
How can you writing was te your readers time with crap like this??? Well now I know wich writers shouldn't read anymore... Such a waste Of time...
Cancel
Ridiculous, if its a numeric field.

Why don't you multiply it by 100 for the column.
Cancel

## SearchDataManagement

• ### Cross-platform integration, data preparation process grows in cloud

While cloud computing may be convenient and more cost-effective for users, it can also lead to new challenges and requirements in...

• ### Graph data model cements tight relationships between data elements

Graph databases can help define and discover relationships between entities -- and offer increased flexibility and better ...

• ### Microsoft SQL Server 2016 relational DBMS overview

Microsoft SQL Server 2016 for Windows comes in four editions, with updates that include a new stretch database feature, Polybase,...

• ### Difficulties in hiring data scientists can waylay analytics efforts

Advanced analytics software provides a lot of functionality, but finding skilled data scientists who can use the available tools ...

• ### Creative projects leave people guessing about future impact of AI

A push is underway to write creative AI algorithms that can engage in music, film and design projects. So far, they have ...

## SearchSAP

• ### Hillarys Blinds speeds SAP S/4HANA upgrade with Panaya tool

Hillarys Blinds, a veteran of several SAP ECC upgrades, completed a move to SAP S/4HANA in just six months using the Panaya ...

• ### Charlotte Hornets build data warehouse with SAP HANA-based Phizzle

The Charlotte Hornets implemented Phizzle FanTracker, an SAP HANA-based platform, to consolidate fan records from many data ...

• ### Does SAP ONE Support Launchpad make SAP support any easier to use?

The new Fiori user experience makes it easier to access applications and support services, but product-specific support still ...

## SearchSQLServer

• ### SQL Server on Linux signals Microsoft's changing development landscape

Expert Joey D'Antoni explains what SQL Server on Linux and the addition of Enterprise Edition features to Standard Edition say ...

• ### How to get the most out of virtual SQL Server with Microsoft Hyper-V

SQL Server is a CPU-intensive technology, which can make it tricky to run in a virtualized environment. Keep your SQL Server ...

• ### Microsoft previews SQL Server on Linux, opens features across editions

Microsoft looks to broaden the horizons of SQL Server, as it moves some Enterprise features to Standard Edition and issues the ...

## TheServerSide

• ### Docker instances become the new norm and adoption goes mainstream

Many organizations use Docker instances for many reasons, although security, data storage and monolithic fears remain barriers to...

• ### How to turn your DevOps failures into ALM successes

Doing the right thing doesn't always mean you're doing things right. But don't fret, because short-term DevOps failures can mean ...

• ### From chatbots to IBM's Watson: How software deals with conversational language

The next big thing in software development is conquering the conversational language development hurdle. Here's how the big ...

## SearchDataCenter

• ### Build a data center shutdown procedure to prepare for the worst

A data center shutdown checklist helps IT teams focus on backup, testing and system verification before pulling the plug and ...

• ### Telcos purge colocation data centers, open door to neutral connections

Enterprise customers in Verizon and CenturyLink's colocation data centers should expect better cloud and network connection ...

• ### IT slowly embraces composable infrastructure

If there will be a way to make an enterprise data center as efficient and optimized as cloud computing, composable infrastructure...

## SearchContentManagement

• ### Microsoft brings its flavor of AI with Microsoft Cognitive Services

Microsoft Cognitive Services has a new array of APIs to make it easier to scan text, video and audio data and to bring ...

• ### Users prefer Office 365 suite collaboration features over SharePoint

Users don't want to jump through hoops, and they want applications to work on mobile devices. Those needs may kill traditional ...

• ### What new SharePoint features to expect in the next 12 months

Now that Microsoft is developing its SharePoint features, there are new feature rollouts all the time. Here's a rundown of the ...

## SearchFinancialApplications

• ### Foot Locker seeks a good fit with Infor pre-employment assessment tool

Foot Locker is among a growing number of companies using cloud-based pre-hire assessment to screen job applicants for character ...

• ### Project planning for a new corporate performance management system

A corporate performance management system touches most aspects of any business. You need a carefully thought-out plan to ensure a...

• ### No one-size-fits-all strategy for cloud ERP software migration

Experts say a cloud ERP transition plan will vary according to a variety of factors, from company size to an organization's ...

Close