Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query Access table

Author  Topic 

GIS
Starting Member

9 Posts

Posted - 2014-10-22 : 11:57:12
Hello,

I've got 3 columns/fields: Name, Salary and Bonus (Data is the table name).

Ideally I'd like to check, through sql, who is paid more than 10% of his total pay (Salary+Bonus) as Bonus.

How would you write it in sql terms?

SELECT * FROM Data where ...

Thanks

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-10-22 : 12:43:39
Assuming there is only one record per name,
SELECT Name, Salary, Bonus
FROM [Data]
WHERE ISNULL(Bonus,0)/(Salary + ISNULL(Bonus,0)) > 0.1;
Go to Top of Page

GIS
Starting Member

9 Posts

Posted - 2014-10-23 : 02:41:02
James thanks. It doesn't work. For each name there is one bonus and one salary. It returns error - too many arguments. Maybe it has to do with []?
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-10-23 : 08:43:21
I forgot that this is Access. I was writing it for SQL Server. Try
SELECT Name, Salary, Bonus
FROM [Data]
WHERE Bonus/(Salary + Bonus) > 0.1;
Go to Top of Page
   

- Advertisement -