最近工作中写了几个存储过程,需要向存储过程中传递字符串,因为SQL Server 2000中没有内置类似于 split 的函数,只好自己处理,将前台数据集中的一列用逗号拆分存到一个List中,再转化为字符串传给存储过程,很是麻烦。今天看了下SQL Server 2008的新特性,发现有表变量的使用,及其将DataTable作为参数的用法,就尝试了一下,简单谈谈心得。 示例代码下载 一、测试环境 1、Windows Server 2008 R2 DataCenter 2、Visual Studio
1例如:要把如图1的字段拆分图2
select account_id,
substring_index(substring_index(a.related_shop_ids,','
,b.help_topic_id+1),',',-1) shopid
from
sales_hang_account a
join
mysql.help_topic b
on b.help_topic_id < (length(a.related_shop_