日期:2014-05-17 浏览次数:20876 次
SET @strsql='select R.moduleid,username from Modules R inner join(select moduleid,username=dbo.f_str(moduleid) from ModuleHost group by moduleid)T on R.moduleid=1 and R.moduleid=T.moduleid'
-- 1. 创建处理函数 CREATE FUNCTION dbo.f_str(@moduleid int) RETURNS varchar(100) AS BEGIN DECLARE @re varchar(100) SET @re='' SELECT @re=@re+','+username FROM ModuleHost WHERE moduleid=@moduleid RETURN(STUFF(@re,1,1,'')) END GO
SET @strsql='select R.moduleid,M.username from Modules R left join ModuleHost M on R.moduleid = M.moduleid where moduleid=1
------解决方案--------------------
用左连接left join试试