标题: 通过SQL语句生成字段连接串 [打印本页] 作者: 郑全 时间: 2024-4-28 22:25 标题: 通过SQL语句生成字段连接串 declare @strcol varchar(max)='';
declare @strsingle varchar(50)='';
declare column_Cursor CURSOR FOR
select column_name
from INFORMATION_SCHEMA.COLUMNS a
where table_catalog='bak'
and table_name='V_BA_FIRSTPAGE'
--and ORDINAL_POSITION>=750
order by ORDINAL_POSITION;
OPEN column_Cursor;
FETCH NEXT FROM column_Cursor INTO @strsingle;
WHILE @@FETCH_STATUS = 0
begin
set @strcol=@strcol+ ',@' + @strsingle;
FETCH NEXT FROM column_Cursor INTO @strsingle;
end;
--print @strcol select @strcol for xml path ('')
CLOSE column_Cursor;
DEALLOCATE column_Cursor;
go