我已经在SQL Server中创建了一个标量函数。我找不到语法错误。其次,我创建了检查条件的函数。我想知道格式是否正确。请帮助我
CREATE FUNCTION [dbo].[SetRateCalculation]
(
@FromDate Datetime,
@ToDate Datetime
)
RETURNS MONEY
AS
BEGIN
-- Declare the return variable here
RETURN (SELECT CASE WHEN ServiceDate BETWEEN @FromDate AND @ToDate AND CPTDescription LIKE '%GAMMAPLEX%' THEN '4.00'
WHEN ServiceDate BETWEEN @FromDate AND @ToDate AND `enter code here`CPTDescription LIKE '%OCTAGAM%' THEN '38.25'
WHEN ServiceDate BETWEEN @FromDate AND @ToDate AND CPTDescription LIKE'%CARIMUNE%' THEN '26.00'
WHEN ServiceDate BETWEEN @FromDate AND @ToDate AND CPTDescription LIKE '%PRIVIGEN%' THEN '39.98'
WHEN ServiceDate BETWEEN @FromDate AND @ToDate AND CPTDescription LIKE '%GAMUNEX%' THEN '39.98'
WHEN ServiceDate BETWEEN @FromDate AND @ToDate AND CPTDescription LIKE '%GAMMAGARD%' THEN '43.00'
WHEN ServiceDate BETWEEN @FromDate AND @ToDate AND CPTDescription LIKE'%BIVIGAM%' THEN '38.25'
)
END
GO
答案 0 :(得分:1)
CREATE FUNCTION [dbo].[SetRateCalculation]
(
@FromDate Datetime,
@ToDate Datetime
)
RETURNS MONEY
AS
BEGIN
-- Declare the return variable here
RETURN (SELECT CASE WHEN ServiceDate BETWEEN @FromDate AND @ToDate AND CPTDescription LIKE '%GAMMAPLEX%' THEN '4.00'
WHEN ServiceDate BETWEEN @FromDate AND @ToDate AND `enter code here`CPTDescription LIKE '%OCTAGAM%' THEN '38.25'
WHEN ServiceDate BETWEEN @FromDate AND @ToDate AND CPTDescription LIKE'%CARIMUNE%' THEN '26.00'
WHEN ServiceDate BETWEEN @FromDate AND @ToDate AND CPTDescription LIKE '%PRIVIGEN%' THEN '39.98'
WHEN ServiceDate BETWEEN @FromDate AND @ToDate AND CPTDescription LIKE '%GAMUNEX%' THEN '39.98'
WHEN ServiceDate BETWEEN @FromDate AND @ToDate AND CPTDescription LIKE '%GAMMAGARD%' THEN '43.00'
WHEN ServiceDate BETWEEN @FromDate AND @ToDate AND CPTDescription LIKE'%BIVIGAM%' THEN '38.25'
END )
END
GO
答案 1 :(得分:1)
您需要结束案例(https://docs.microsoft.com/en-us/sql/t-sql/language-elements/case-transact-sql?view=sql-server-2017)
CREATE FUNCTION [dbo].[SetRateCalculation]
(
@FromDate Datetime,
@ToDate Datetime
)
RETURNS MONEY
AS
BEGIN
-- Declare the return variable here
RETURN (SELECT CASE
WHEN ServiceDate BETWEEN @FromDate AND @ToDate AND CPTDescription LIKE '%GAMMAPLEX%' THEN '4.00'
WHEN ServiceDate BETWEEN @FromDate AND @ToDate AND `enter code here`CPTDescription LIKE '%OCTAGAM%' THEN '38.25'
WHEN ServiceDate BETWEEN @FromDate AND @ToDate AND CPTDescription LIKE'%CARIMUNE%' THEN '26.00'
WHEN ServiceDate BETWEEN @FromDate AND @ToDate AND CPTDescription LIKE '%PRIVIGEN%' THEN '39.98'
WHEN ServiceDate BETWEEN @FromDate AND @ToDate AND CPTDescription LIKE '%GAMUNEX%' THEN '39.98'
WHEN ServiceDate BETWEEN @FromDate AND @ToDate AND CPTDescription LIKE '%GAMMAGARD%' THEN '43.00'
WHEN ServiceDate BETWEEN @FromDate AND @ToDate AND CPTDescription LIKE'%BIVIGAM%' THEN '38.25'
END -- END CASE
)
END
GO