CREATE FUNCTION dbo.Split(@Str VARCHAR(8000)) RETURNS @List TABLE ( OBJECT VARCHAR(100) ) AS BEGIN DECLARE @OBJECT AS VARCHAR(100) WHILE CHARINDEX(',',@Str)>0 BEGIN SET @OBJECT=SUBSTRING(@Str,1,CHARINDEX(',',@Str)-1) INSERT INTO @List ( OBJECT ) SELECT @OBJECT SET @Str=STUFF(@Str,1,CHARINDEX(',',@Str),'') END RETURN END ------------------------------------------------------------------------ DECLARE @STR VARCHAR(500) SET @STR='2009/01/01,2010/05/01,' SELECT CONVERT(DATETIME,OBJECT) FROM Split(@STR)----DATETIEM SET @STR='1,2,3,4,5,6,7,8,9,10' SELECT CONVERT(INT,OBJECT) FROM Split(@STR)------INT
SQL----类似Split函数的实现1
最新推荐文章于 2022-03-16 14:01:11 发布