SQL Server 编程示例
查询结果存入变量
DECLARE @fserviceuserid VARCHAR(50); SELECT @fserviceuserid=a.fdevicecode FROM dbo.tdmsdevice a WHERE a.frowid='1' --结果,2023050001 select @fserviceuserid
查询结果拼接并存入变量
DECLARE @fserviceuserid VARCHAR(5000); SET @fserviceuserid=(SELECT STRING_AGG(a.fdevicecode,'|') FROM dbo.tdmsdevice a WHERE a.fdevicecode like '%0001%') --结果,2023050001|2023060001|2023070001 select @fserviceuserid as devicecode
标签:dbo,fserviceuserid,编程,Server,fdevicecode,SQL From: https://www.cnblogs.com/microsoft-zh/p/17722253.html