when using the following code in my function, I'm getting errors. Is it possible to set a variable and then use it in a function as follows?
if OBJECT_ID ('tvf_Inline_Te st') is not null
drop function tvf_Inline_Test
go
create function tvf_Inline_Test (@vstrDate char(15),
@VSTRDTYR char(15),
@mydatevar char(15),
@thismo as char(15))
set @thismo = right ('00' + CAST(DATEPART(M onth, getdate()) AS VARCHAR(2)),2)
set @vstrDate = right ('00' + CAST(DATEPART(M onth, getdate())-7 AS VARCHAR(2)),2)
--set @VSTRDTYR = CAST(DATEPART(Y YYY, GETDATE()) AS VARCHAR(4))
SELECT @VSTRDTYR =
CASE
WHEN @thismo = 12 THEN CAST(DATEPART(Y YYY, GETDATE())-1 AS VARCHAR(4))
ELSE CAST(DATEPART(Y YYY, GETDATE()) AS VARCHAR(4))
END
set @mydatevar = LTRIM(RTRIM(@VS TRDTYR)) + '/' + LTRIM(RTRIM(@vs trDate))
returns table
as
return select wellID,yearmont h
from well_summary where well_summary.ye armonth = @mydatevar
go
if OBJECT_ID ('tvf_Inline_Te st') is not null
drop function tvf_Inline_Test
go
create function tvf_Inline_Test (@vstrDate char(15),
@VSTRDTYR char(15),
@mydatevar char(15),
@thismo as char(15))
set @thismo = right ('00' + CAST(DATEPART(M onth, getdate()) AS VARCHAR(2)),2)
set @vstrDate = right ('00' + CAST(DATEPART(M onth, getdate())-7 AS VARCHAR(2)),2)
--set @VSTRDTYR = CAST(DATEPART(Y YYY, GETDATE()) AS VARCHAR(4))
SELECT @VSTRDTYR =
CASE
WHEN @thismo = 12 THEN CAST(DATEPART(Y YYY, GETDATE())-1 AS VARCHAR(4))
ELSE CAST(DATEPART(Y YYY, GETDATE()) AS VARCHAR(4))
END
set @mydatevar = LTRIM(RTRIM(@VS TRDTYR)) + '/' + LTRIM(RTRIM(@vs trDate))
returns table
as
return select wellID,yearmont h
from well_summary where well_summary.ye armonth = @mydatevar
go
Comment