tsql - “Incorrect syntax” using a table-valued function in SELECT clause of T-SQL query -
i have sql 2008 database compatibility level of 80 (i.e. sql 2000). have been able use cross apply functions, when add table-valued function, not allow me proceed.
i have member ids following format:
ebs_322002_0397204_e
i need second piece of dynamically, since first piece may not been 3 characters long; otherwise, use substring function , call day.
this split function:
alter function [dbo].[fnsplit] (@sep char(1),@string varchar(8000)) returns table --with schemabinding return ( pieces(pn, [start], [stop]) ( select 1, 1, charindex(@sep, @string) union select pn + 1, [stop] + 1, charindex(@sep, @string, [stop] + 1) pieces [stop] > 0 ) select pn, substring(@string, [start], case when [stop] > 0 [stop]-[start] else len(@string) end) string pieces
)
first attempt:
with members ( select distinct memberid mytable ) select * members m cross apply dbo.fnsplit('_',m.memberid) b
produced error:
msg 102, level 15, state 1, line 7 incorrect syntax near 'm'.
second attempt (to around compatibility issue):
with members ( select distinct memberid mytable ) select * members m outer apply ( select top 1 string groupnum dbo.fnsplit('_', m.memberid) order pn desc ) step1
produced following error:
msg 102, level 15, state 1, line 11 incorrect syntax near 'm'.
i have been beating head against wall few hours , now, not know do... suggestions?
Comments
Post a Comment