I have written an inline TVF and I have this so far. I get this error:incorrect syntax near end. Can someone suggest a workaround for this. Can i actually do it thsi way syntactically, is it correct?
CREATE FUNCTION [hsip].[Question_Dtl_Table_Id]
(
-- Add the parameters for the function here
@cRegion CHAR(2) ='00',
@cState_Code CHAR(2) = '00',
@nFY NUMERIC(4,0) = 0,
@nREPORT_ID NUMERIC(2,0) = 0,
@nSECTION_ID NUMERIC(2,0) = 0,
@nSUBSECTION_ID NUMERIC(2,0) = 0,
@nDISPLAY_NUMBER NUMERIC(38,0) = 0,
@nQUESTION_NUMBER NUMERIC(38,0) = 0,
@nQUESTION_PART_NUMBER NUMERIC(38,0) = 0,
@sUSER_ID VARCHAR(25) = NULL
)
RETURNS @tbl TABLE ( Region CHAR(2),
State_Code CHAR(2),
FY NUMERIC(4,0),
REPORT_ID NUMERIC(2,0),
SECTION_ID NUMERIC(2,0),
SUBSECTION_ID NUMERIC(2,0),
DISPLAY_NUMBER NUMERIC(38,0),
QUESTION_NUMBER NUMERIC(38,0),
QUESTION_PART_NUMBER NUMERIC(38,0),
USER_ID VARCHAR(25))
AS
--RETURN
begin
INSERT INTO @tbl
select * from (SELECT qi.REGION, qi.STATE_CODE, qi.FY, qi.REPORT_ID, qi.SECTION_ID, qi.SUBSECTION_ID, qi.DISPLAY_NUMBER,
qi.QUESTION_NUMBER, qd.QUESTION_PART_NUMBER from
FY_ST_QUESTION_INFO qi
inner join
FY_ST_QUESTION_DETAIL qd
on qi.FY_ST_QUESTION_INFO_TABLE_ID= qd.FY_ST_QUESTION_INFO_TABLE_ID
where qi.region= @cRegion
and qi.fy= @nFY
and qi.REPORT_ID = @nREPORT_ID
and qi.SECTION_ID = @nSECTION_ID
and qi.SUBSECTION_ID = @nSUBSECTION_ID
and qi.DISPLAY_NUMBER =@nDISPLAY_NUMBER
and (qi.REPORTER_ID = @sUSER_ID or
qi.DELEGATE_ID= @sUSER_ID or
qi.SUB_DELEGATE_ID = @sUSER_ID));
return;
end
Thanks