Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert MSAccess function to SQL Server function

Status
Not open for further replies.

susrutha

Programmer
Oct 12, 2001
2
US
Can anybody please help me to convert this Access function to SQL Server function?

Public Function MarginPercent(pCost As Currency, pRetail As Currency) As Double
If pRetail = 0 Then
MarginPercent = 0
Else
If pCost = 0 Then
MarginPercent = 1
Else
MarginPercent = 1 - (pCost / pRetail)
End If
End If
End Function

Thanks,
Susrutha.
 
You could try, but you may have to adjust the data types as I do not know what size numbers you are actuallly dealing with:

CREATE FUNCTION [dbo].[MarginPercent] (@pCost money, @pRetail money)
RETURNS decimal (9, 2)
AS
BEGIN
Declare @Percent as decimal (9, 2)

If @pRetail = 0
Set @Percent =0
Else
If @pCost = 0
Set @Percent =1
Else
set @Percent = 1 - (@Pcost/@PRetail)

Return @Percent

END

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top