I have a test I have to use regularly in queries to see if a CPT billing code is a billable encounter. In the SQL query, the test looks like this:
where (pvp.code between '99201' and '99215'
or pvp.code between '99221' and '99239')
plus a whole bunch more ranges.
I tried to create a function by just plugging this in to the function, but I got an “incorrect syntax” error — not a huge surprise, really.
CREATE FUNCTION IsEncounter
(
@code varchar(20)
)
RETURNS bit
AS
BEGIN
DECLARE @Result bit;
SELECT @Result = @code between '99201' and '99215'
or @code between '99221' and '99239';
-- Return the result of the function
RETURN @Result;
END
I suppose I can do something like
if (@code >= '99201' and @code <= '99215')
or (@code >= '99221' and @code <= '99239')
select @Result = 1
else
select @Result = 0;
but I’d like to know the cleanest way to do this. Thanks.
Something like this should work: