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
 Stuck on a Fucntion

Author  Topic 

Rhino9
Starting Member

3 Posts

Posted - 2006-05-07 : 12:41:22
I am attempting to write a function to Check the price of every disk and return the number of titles ont he disk which has the highest price. I do not even think that I am in the ballpark:

CREATE FUNCTION highest_price ( )

BEGIN

SELECT count(*) AS
FROM Disk
WHERE price = (SELECT max(price) FROM Disk);

END
/


MusicalWork (idwork, title)
Piece (idpiece, duration, iddisk, idwork)
Disk (iddisk, brand, type, issuingdate, price)
Execute (idpiece, idinterpreter)
Interpreter (idinterpreter, name, address)


Thank you in advance!

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-05-07 : 18:01:10
[code]
CREATE FUNCTION highest_price ( )
RETURNS INT
BEGIN
RETURN (
SELECT count(*) AS NUMTITLES
FROM Disk
WHERE price = (SELECT max(price) FROM Disk)
)
END
[/code]


KH

Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-05-08 : 03:39:09
Read about User Defined Functions(UDF) in Book Online...

If Debugging is the process of removing Bugs then i Guess programming should be process of Adding them.
Go to Top of Page
   

- Advertisement -