Declare @Table table (Name varchar(100), ValueType varchar(100))
DECLARE @ConcatString varchar(100)
insert into @Table values
('idGasto','int'),
('noTicket','String'),
('fechaFact','String'),
('fecha','String'),
('concepto','String')
--If you're on at least SQL Server 2017, you can use STRING_AGG
select @ConcatString = STRING_AGG(Name + ' ' + ValueType, ',')
from @table
print @ConcatString
这是你想要的?
注意:如果您至少使用 SQL Server 2017,则可以使用
STRING_AGG
:您还可以使用 COALESCE