有一张表,数据如下
编写如下sql语句
/****** Script for SelectTopNRows command from SSMS ******/ declare @output nvarchar(max) declare @year char(4) declare @startdate datetime declare reader cursor for SELECT distinct TOP 10 [cme_year] ,[start_date] FROM [ayn_cme_year] order by cme_year open reader fetch next from reader into @year,@startdate while @@fetch_status=0 begin set @output=@output+convert(nvarchar(4),@year)+' '+convert(nvarchar(10),@startdate)+' ' fetch next from reader into @year,@startdate end select @output close reader deallocate reader
执行之后无结果,为什么?
在使用@output之前初始化一下就对了 set @output=''