sql-server-2005: How to perform a split on a pipe delimited string variable?
问题 i have simple data coming in like this: declare @string varchar(500) = "val1|val2|val3" how could i split this out into a cte or something similar so i could user it in a later query: select col1 from table where col2 = @valFromCTE 回答1: This is a helpful and simple way to query a delimited string as if it were a table. Taken from: http://www.mindsdoor.net/SQLTsql/ParseCSVString.html if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[fn_ParseCSVString]') and xtype in (N'FN',