1. 主页 > 分享干货

sql连接字符串的方法(sqlserver连接字符串)

方案一:

Create FUNCTION [dbo].Get_Contract_StyleNo(@AutoInc bigint)

RETURNS VARCHAR(Max)

AS

BEGIN

declare @Content NVARCHAR(MAX)

SET @Content = ”

select @Content = case when @Content=” then ” else @Content + ‘,’ end + GoodsNo

FROM (select distinct GoodsNo from EXP_Contract_Clothing_Goods where MainID=@AutoInc) m

RETURN @Content

END

GO

构造标量函数

使用xml

构造通用存储过程

方案三:

——默认条件,MainID=AutoInc

alter procedure [dbo].[SP_SumStr]

(

@MTable Varchar(100)–主表

,@ZTable Varchar(100)–子表

,@MColumn Varchar(100)–主表更新字段

,@ZColumn Varchar(100)–子表拼接字段

,@ConditionSql Varchar(500)–传入的条件语句

)

as

set nocount on

begin

declare @strSql varchar(3000)

select top 1 AutoInc as MainID, Convert(nvarchar(500),CnName) as GoodsNo

into #result

from SYS_Staff where 1<0

set @strSql = ‘insert into #result select distinct MainID,’+ @ZColumn +’ from ‘+@ZTable+’ ‘ + @ConditionSql

exec(@strSql)

declare @Content NVARCHAR(MAX)

SET @Content = ”

select @Content = case when @Content=” then ” else @Content + ‘,’ end + GoodsNo FROM #result

set @strSql = ‘update a set a.’+@MColumn+’=’+@Content+’ from ‘+ @MTable +’ a left join ‘+@ZTable+’ b on a.AutoInc=b.MainID ‘ + @ConditionSql

exec(@strSql)

—-select @Content

end

set nocount off

本文内容由互联网用户自发贡献,该文观点仅代表作者本人。如发现本站有涉嫌抄袭侵权/违法违规的内容,请发送邮件至 203304862@qq.com

本文链接:https://jinnalai.com/fenxiang/51417.html

联系我们

在线咨询:点击这里给我发消息

微信号:

工作日:9:30-18:30,节假日休息