Q
Problem solve Get help with specific problems with your technologies, process and projects.

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

• Apache Hadoop 3.0 goes GA, adds hooks for cloud and GPUs

Is this the post-Hadoop era? Not in the eyes of Hadoop 3.0 backers, who see the latest update to the big data framework ...

• Expert: For BI, you must know the data integration process

Understanding the data integration process is central to self-service BI and data architecture design, consultant Rick Sherman ...

• Graph technology rivals take Amazon Neptune database in stride

Amazon's Neptune database may change the status quo in the graph technology world. But it could also introduce a wider base of ...

• Predictive analytics projects can bolster business decisions

Blind faith in predictive models can result in flawed business decisions. Analytics teams need to manage predictive processes ...

• How predictive analytics techniques and processes work

Predictive analytics is no longer confined to data scientists and other highly skilled analysts. But other users need to ...

• Hyper engine aims to give enterprise Tableau analytics a boost

The Hyper in-memory data engine added in Tableau 10.5 could make Tableau analytics capabilities more expansive, enabling the ...

SearchSAP

• SAP S/4HANA Cloud and indirect access will dominate 2018

Industry experts say SAP S/4HANA Cloud migrations, Leonardo and Cloud Platform are the technology issues for SAP in 2018; on the ...

When a Dutch energy grid provider needed to develop new business apps on top of SAP ERP, it turned to the Mendix RAD platform to ...

• SAP's Timo Elliott on enterprise chatbot AI technology

The SAP global innovation evangelist expects AI to affect businesses in three ways: human-computer interaction, automation of ...

SearchSQLServer

• Meltdown and Spectre fixes eyed for SQL Server performance issues

Microsoft has responded to the Spectre and Meltdown chip vulnerabilities with patches and other fixes. But IT teams need to sort ...

• Five SQL Server maintenance steps you should take -- ASAP

Putting off SQL Server administration tasks can lead to database problems. Enact these often-neglected maintenance items to help ...

• Microsoft Cosmos DB takes Azure databases to a higher level

Azure Cosmos DB brings a new element to the database lineup of Microsoft's cloud platform, offering multiple data models and a ...

TheServerSide.com

• Spring creator Rod Johnson releases API for implementing DevOps

Find out about Rod Johnson's latest project, which promises to simplify the process of implementing DevOps and streamlining the ...

• What Java developers need to know about TypeScript syntax

For Java developers transitioning into JavaScript frameworks, like React and Angular, this TypeScript tutorial on syntax will ...

• AWS Cloud9 IDE threatens Microsoft developer base

With its Cloud9 IDE, AWS challenges Microsoft where it matters most -- with the developer community, where Microsoft has ...

SearchDataCenter

• Three requirements for a hybrid cloud computing deployment

As the hybrid cloud computing approach gains steam, organizations will need to pay close attention to cross-cloud connectivity ...

• Five debunked myths about SSD issues

Solid-state drives are mature now, and the technology has eclipsed hard disk drives with superior performance, manageability and ...

• Future data center trends hinge on the edge, cloud and staffing

Edge computing, colocation, cloud and IT staffing issues lead the way as industry analysts make their predictions for the future ...

SearchContentManagement

• Intelligent information management the next wave for ECM

In a 2018 upgrade, M-Files allows users to search for content in multiple repositories, while also being able to automatically ...

• SharePoint integration and implementation best practices

Here are some expert advice and tips, as well common definitions, to help make your SharePoint integration and implementation a ...

• SharePoint branding capabilities get a facelift

Since Microsoft Ignite last September, SharePoint Online is getting new branding capabilities that have been on the wish lists of...

SearchFinancialApplications

• Finance IT case study: Reporting secrets of Derek Rose

CEO Sacha Rose says specialist reporting tools have saved the company thousands by avoiding unnecessary mistakes.

• WestJet turns to gamification to help its Oracle ERP users soar

WestJet's initial gamification project focuses on expense reporting.

• The Transformation of HR is Underway

HR is being transformed while we watch.

Close