仔细研究后在csdn上找到了解决该问题的办法帖出来给大家共享一下
成都创新互联主营永州网站建设的网络公司,主营网站建设方案,app开发定制,永州h5微信小程序搭建,永州网站营销推广欢迎永州等地区企业咨询
大致方法是利用传递长字符串的形式向存储过程传递一个长字符串。由于sqlserver没有 splite函数
所以必须自己定义一个splite函数来进行处理
自定义一个函数
create function f_splitstr(@SourceSql varchar(8000),@StrSeprate varchar(10))
returns @temp table(F1 varchar(100))asbegindeclare @i int
set @SourceSql=rtrim(ltrim(@SourceSql))
set @i=charindex(@StrSeprate,@SourceSql)while @i=1begininsert @temp values(left(@SourceSql,@i-1))
set @SourceSql=substring(@SourceSql,@i+1,len(@SourceSql)-@i)
set @i=charindex(@StrSeprate,@SourceSql)endif @SourceSql''
insert @temp values(@SourceSql)returnend-执行select * from dbo.f_splitstr('1,2,3,4',',')
注:'1,2,3,4'即你所传递的字符串
同样你可以通过 select cunt(*) from dbo.f_splitstr('1,2,3,4',',')
获得该字符串数组的长度
如果要删除该函数使用--删除函数drop function fsplit
确切的说不行-SQL SERVER没有数组类型,ANSI SQL 92标准也不支持数组。但可用其它的方法来实现。 1. You could simulate an array by passing one or more varchar(255) fields with comma-separated values and then use a WHILE loop with PATINDEX and SUBSTR to extract the values. 1、你可以使用几个VARCHAR(255)字段来模拟数组,字段中用逗号分开各个数据,然后使用循环和PATINDEX和SUBSTR分开这些数据。 2. The more usual way to do this would be to populate a temporary table with the values you need and then use the contents of that table from within the stored-procedure. Example of this below2、通常这种方法需要为这些数据创建一个临时表,然后在存储过程使用表中的内容。如下例create procedure mytest @MyParmTempTable varchar(30)asbegin-- @MyParmTempTable contains my parameter list... 这个变量是包含参数的表名-- For simplicity use dynamic sql to copy into a normal temp table... create table #MyInternalList ( list_item varchar( 2 ) not null)set nocount oninsert #MyInternalList select * from sysobjects create table #MyList ( list_item varchar( 2 ) not null)insert #MyList values ( 'S' ) insert #MyList values ( 'U' ) insert #MyList values ( 'P' )exec mytest "#MyList"3. If all you wanted to do was use the array/list as input to an IN clause in a WHERE statement you could use :-3、如果你想在IN子句里使用输入的数组参数可以这样做:CREATE PROCEDURE sp_MyProcedure (@MyCommaDelimitedString
存储过程里定义不了数组。如果是sqlserver,那么你可以用表变量,游标来实现你的功能。
如果是sqlserver2005以上的版本,可以做clr存储过程,那里面是可以用数组的。
如果是一维数组:$nams=implode(',',
ArrarLIst);
select
*
from
table1
where
name
in
($names);
//注意字符查询需要前后带引号,数字不用
如果是多维数组:得遍历ArrarLIst数组,取出相应的name再串联起来
网页标题:sqlserver中数组,sql server 定义数组
本文URL:https://www.cdcxhl.com/article48/hcgphp.html
成都网站建设公司_创新互联,为您提供网站导航、商城网站、定制开发、用户体验、品牌网站建设、定制网站
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联