Procedure 存储过程
创建存储过程:
create proc ProductList
go
as
begin
select p.productID,p.Name from Product as p
end
想进行修改,输出类型为nvarchar(max)的数据;nvarchar是productID拼接而成的
declare @provarchar nvarchar(max)
set @provarchar=productID1+","+productID2+","+productID3+","+…+productIDn
[解决办法]
create table Product ( productID varchar(10), name varchar(100))--测试数据insert into Product select 'product1','aaa' union allselect 'product2','bbb' union allselect 'product3','ccc' union allselect 'product4','ddd'CREATE PROC ProductList@provarchar nvarchar(max) OUTPUT -- 要输出的参数ASBEGIN select @provarchar=isnull(@provarchar+',' , '')+ productID from ProductENDDECLARE @ProductList nvarchar(max)EXEC ProductList @ProductList OUTPUTselect @ProductList--结果--product1,product2,product3,product4