The code that is building the table variable works great outside of the code creating the function. Once I add it the the function, it would not parse.
Am I dealing with a syntax issue here? I know that I can not use a temp table in this function, which is the reason why I am going with a table variable (@T_stage).
Thanks a lot.
CREATE function new_function
declare @T_stage TABLE (field1 VARCHAR(40) NOT NULL,
field2 NVARCHAR (10) NOT NULL PRIMARY KEY,
field3 DATETIME NULL)
select MAX (LEGAL_NM) AS LEGAL_NAME,
MAX (TCPRL.VEND_CO_ID) AS VEND_CO_ID,
MAX(tcx.max_process_date) as LTST_PROCESSED_CHK_DATE
FROM t_bps_company_extract TCX
WHERE TCX.Company_status = 'Active'
group by TCPRL.vend_co_id, TCX.LEGAL_NM