Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 2008 在SQL Server字符串中拆分数据_Sql Server 2008 - Fatal编程技术网

Sql server 2008 在SQL Server字符串中拆分数据

Sql server 2008 在SQL Server字符串中拆分数据,sql-server-2008,Sql Server 2008,3106分 967个员额 在SQL Server字符串中拆分数据 25分钟前|链接 大家好 我有两个逗号分隔的字符串,一个有控件名,另一个有它的值,我将这些值连同需要插入数据的表名一起发送到存储过程 现在,如何在SQLServer2008中拆分这些字符串并形成插入查询 另外,我有一个表,我在其中维护了控制值应该存储在哪一列 所以我需要使用这个来形成insert查询?如何操作?此函数将帮助您拆分字符串: CREATE function dbo.split(@value varchar(8000),

3106分

967个员额 在SQL Server字符串中拆分数据

25分钟前|链接

大家好

我有两个逗号分隔的字符串,一个有控件名,另一个有它的值,我将这些值连同需要插入数据的表名一起发送到存储过程

现在,如何在SQLServer2008中拆分这些字符串并形成插入查询

另外,我有一个表,我在其中维护了控制值应该存储在哪一列


所以我需要使用这个来形成insert查询?如何操作?

此函数将帮助您拆分字符串:

CREATE function dbo.split(@value varchar(8000),@delim varchar(8000))
returns table
as
return
(
select d.value,
       d.orders,
       ivalue = convert(int, case when isnumeric(d.value)=1 and d.value not like '%[^0-9 +-]%' and len(replace(replace(replace(d.value,' ',''),'-',''),'+',''))<=10 then case when convert(bigint,d.value) between -2147483648 and 2147483647 then d.value end end)

    from
        (
            select   
                    value= replace(substring(value,
                                            idx,
                                            case when cnt>=0 then cnt end /* case для защиты от нехороших планов, когда сначала идет вычисление substring, а потом ограничивающее where по s_value.number between */
                                         )
                                 ,char(1),'')
                    ,orders=( datalength(left(value,idx-1))-datalength(replace(left(value,idx-1),@delim,''))
                            )/datalength(@delim)
                from (
                       select number
                             ,idx
                             ,cnt = charindex(@delim,value, number + 1) - number - datalength(@delim)
                             ,value 
                          from 
                                (
                                   select number
                                         ,idx = number + datalength(@delim)
                                         ,value = (select @delim+char(1)+@value+char(1)+@delim)
                                      from dbo.s_value
                                        where number between 1 and datalength( (select @delim+char(1)+@value+char(1)+@delim) ) - datalength(@delim)

                                ) t            
                          where substring(t.value, number, datalength(@delim)) = @delim         
                     ) t             
       ) d          
)


GO