这语句什么写?

SQLANDGAO 2005-03-05 12:07:11
select A,B from WorkingProcedureInstance where zgid=10025
执行后的结果如下:
A B
双层板 10016;10007;10002;10006;
问:
我想把上面的结果插入到这样的一个表(表2)
A B
双层板 10016
双层板 10007
双层板 10002
双层板 10006

应该什么写效率最高?谢谢
...全文
57 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
631799 2005-03-05
  • 打赏
  • 举报
回复
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_split]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[f_split]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[序数表]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [序数表]
GO

--为了效率,所以要一个辅助表配合
select top 8000 id=identity(int,1,1) into 序数表
from syscolumns a,syscolumns b
alter table 序数表 add constraint pk_id_序数表 primary key(id)
go

/*--字符串分函数

分拆指定分隔符的的字符串,返回结果表

--邹建 2004.04(引用请保留此信息)--*/

/*--调用示例

select * from f_split('考号kaohao 科目kemu 学期xueqi',' ')
--*/
create function f_split(
@str varchar(8000), --要分拆的字符串
@splitchar varchar(10) --分隔符
)returns table
as
return(
select re=substring(@str,id,charindex(@splitchar,@str+@splitchar,id)-id)
from 序数表
where id<=len(@str)+1 and charindex(@splitchar,@splitchar+@str,id)-id=0
)
go
bitsbird 2005-03-05
  • 打赏
  • 举报
回复
create function getstrofindex (@str varchar(8000),@index int =0)
returns varchar(8000)
as
begin
declare @str_return varchar(8000)
declare @start int
declare @next int
declare @location int
select @start =1
select @next =1
select @location = charindex(',',@str,@start)
while (@location <>0 and @index > @next )
begin
select @start = @location +1
select @location = charindex(',',@str,@start)
select @next =@next +1
end
if @location =0 select @location =len(@str)+1
select @str_return = substring(@str,@start,@location -@start)
if (@index <> @next ) select @str_return = ''
return @str_return
end
go
select dbo.getstrofindex('1,2,4',3)
FigoChoi 2005-03-05
  • 打赏
  • 举报
回复
用游标

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧