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
 Problem with greater than derived value

Author  Topic 

Ichiro Sato
Starting Member

5 Posts

Posted - 2008-06-01 : 23:30:40
im supposed to output the companies that have commission rates highter than company "Industrial Appparatus".
is there some whay to modify this code so that it will work?
commissionrate > ALL(Select commissionRate From salescompanydomestic Where companyName = 'Industrial Appparatus')

raky
Aged Yak Warrior

767 Posts

Posted - 2008-06-02 : 00:29:55
quote:
Originally posted by Ichiro Sato

im supposed to output the companies that have commission rates highter than company "Industrial Appparatus".
is there some whay to modify this code so that it will work?
commissionrate > ALL(Select commissionRate From salescompanydomestic Where companyName = 'Industrial Appparatus')



SELECT
CompanyName,commissionrate
FROM
salescompanydomestic
WHERE
commissionrate > ( SELECT commissionRate FROM salescompanydomestic
WHERE companyName = 'Industrial Appparatus')
Go to Top of Page

Ichiro Sato
Starting Member

5 Posts

Posted - 2008-06-02 : 00:32:53
When i try that i get this error
Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-02 : 00:33:46
For giving a soln on this, we need more info on your table structure with some sample data. Could you post them please?As of now i can only tell it would be something like
SELECT * FROM YourTable
WHERE commissionrate > (SELECT MAX(commissionrate) From salescompanydomestic Where companyName = 'Industrial Appparatus')
Go to Top of Page

Ichiro Sato
Starting Member

5 Posts

Posted - 2008-06-02 : 00:37:57
I have two tables that I am using for this query
SalesCompany
companyId companyName salesNetworkIndicator
----------- ------------------------------ ---------------------
111 Industrial Appparatus D
222 AIE Inc D
333 Chalman Technologies D
444 Langley Macinery D
555 Electronic Assembly Products D
666 KDF Company D
777 AKA Northern Asia I
888 Algon EAPRO I
999 Algon France I
1000 3D Automation India I
1100 Enlaces Industriales I
1200 Townsend Coates Ltd I

(12 row(s) affected)

SalesCompanyDomestic
companyId state phone commissionRate
----------- -------------------- -------------------- ---------------------------------------
111 Alabama 770-9191913 0.0300
222 Alaska 425-4554697 0.0500
333 California 714-5651234 0.0100
444 Florida 352-1234343 0.0200
555 Utah 303-1235465 0.0400
666 Ohio 440-9897867 0.1000

(6 row(s) affected)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-02 : 00:43:50
quote:
Originally posted by Ichiro Sato

I have two tables that I am using for this query
SalesCompany
companyId companyName salesNetworkIndicator
----------- ------------------------------ ---------------------
111 Industrial Appparatus D
222 AIE Inc D
333 Chalman Technologies D
444 Langley Macinery D
555 Electronic Assembly Products D
666 KDF Company D
777 AKA Northern Asia I
888 Algon EAPRO I
999 Algon France I
1000 3D Automation India I
1100 Enlaces Industriales I
1200 Townsend Coates Ltd I

(12 row(s) affected)

SalesCompanyDomestic
companyId state phone commissionRate
----------- -------------------- -------------------- ---------------------------------------
111 Alabama 770-9191913 0.0300
222 Alaska 425-4554697 0.0500
333 California 714-5651234 0.0100
444 Florida 352-1234343 0.0200
555 Utah 303-1235465 0.0400
666 Ohio 440-9897867 0.1000

(6 row(s) affected)


SELECT *
FROM SalesCompanyDomestic scd
INNER JOIN SalesCompany sc
ON sc.companyId=scd.companyId
WHERE scd.commissionRate >
(
SELECT scd.commissionRate
FROM SalesCompanyDomestic scd
INNER JOIN SalesCompany sc
ON sc.companyId=scd.companyId
AND sc.CompanyName='Industrial Appparatus')
Go to Top of Page

Ichiro Sato
Starting Member

5 Posts

Posted - 2008-06-02 : 00:47:04
Thanks!
Go to Top of Page
   

- Advertisement -