sqlserver连接字符串(sql连接字符串的方法)
方案一:
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
免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com