declare @str varchar(max)
select @str=ISNULL(@str+':','')+ProductNo from (select distinct top 10 ProductNo from ProductTB)as temp
select @str
此篇博客介绍了如何使用SQL动态生成字符串,展示了如何利用ISNULL函数和聚合函数从ProductTB表中获取前10个不同的产品编号,并将其添加到变量@str中。
declare @str varchar(max)
select @str=ISNULL(@str+':','')+ProductNo from (select distinct top 10 ProductNo from ProductTB)as temp
select @str

被折叠的 条评论
为什么被折叠?