I have a query that runs perfectly and it uses a function fn_split. It works just fine but when I put this query in a procedure it no longer works and tells me that fn_split is undefined?... Any ideas? I would also like to know what the ; infront of the with is for if someone would enlighten me. THANKS!
working query:
failing SP:
working query:
Code:
Declare
@OrderList varchar(50)
set @OrderList = replace('SBCORD10949415, SBCORD10953377',' ','')
;with cte as (select * from fn_split(@OrderList,','))
select T.GPItemNumber, cte.*, case when T.OrderNumber IS NULL then 0 else 1 end as hasItem from cte LEFT JOIN UserTemplate T on cte.cValue = T.OrderNumber
Code:
ALTER PROCEDURE [dbo].[procGetItemnumbers]
@OrderList varchar(50)
AS
SET NOCOUNT ON;
;with cte as (select * from fn_Split(@OrderList,','))
select T.GPItemNumber, cte.*, case when T.OrderNumber IS NULL then 0 else 1 end as hasItem from cte LEFT JOIN UserTemplate T on cte.cValue = T.OrderNumber