--SQL server 2005 表中某一字段的所有值逗号分开的列表Geovin Du 塗聚文select * from Production.Productdeclare @names varchar(50)set @names=''select @names=@names+s.Name+' , 'from Production.Product sorder by s.Nameselect @namesgo--sql server 2000 如何逐条读出表中某一字段的所有值 Geovin Du 塗聚文declare @allstring varchar(8000)set @allstring=''select @allstring=@allstring+convert(varchar(10),PublicHolidayID)+';' from PublicHolidayRest print @allstringGO
--查询字符中包函的结果declare @sql varchar(500),@in varchar(500),@where varchar(800),@allstring varchar(8000) set @sql='select * from intranet.dbo.v_lc 'set @allstring=''select @allstring=@allstring+''''+BranchNO+''''+',' from intranet.dbo.v_lc where ServiceCardNo='008888'set @allstring=left(@allstring,len(@allstring)-1)set @where=@allstringset @in=' where BranchNO in ('+@where+')'set @sql=@sql+@inprint @sqlprint @allstring exec (@sql)GO