|
楼主 |
发表于 2017-12-14 08:55
|
显示全部楼层
create PROCEDURE [dbo].[UDF_P_GETUnAuditList]
@DATE CHAR(8)
AS
BEGIN
SELECT G.TG001 AS MQ001, Q.MQ002 AS MQ002, G.TG002 AS OrderNum, G.TG003 AS OrderDate, G.CREATOR AS CREATOR,
G.CREATE_DATE AS CREATE_DATE, G.MODIFIER AS MODIFIER, G.MODI_DATE AS MODI_DATE ,G.TG049 as DeptID,
(case when NOT exists(select 1 from PURTH where TH001=G.TG001 and TH002=G.TG002) then '空单身' end) as BZ,
(STUFF((SELECT DISTINCT ','+RTRIM(TH009)+'('+RTRIM(MC002)+')' FROM PURTH LEFT JOIN CMSMC ON TH009=MC001
WHERE TH001=G.TG001 AND TH002=G.TG002 FOR XML PATH('')),1,1,'')) AS CK
FROM dbo.PURTG AS G
LEFT JOIN dbo.CMSMQ AS Q ON Q.MQ001=G.TG001
WHERE G.TG013='N' AND Q.MQ003='34'
and (G.TG003<= @DATE OR G.TG003 IS NULL )
end
这个是存储过程,在数据库里面执行是正常的!
VBA里面调用
strcon = "Driver={SQL Server};Server=" & server & ";UID=" & uid & ";PWD=" & pwd & ";DataBase=" & db
cn.Open strcon
strsql = "exec UDF_P_GETUnAuditList '" & Me.txtEndDate.Text & "'" '参数可选
'rs.Open strsql, cn, adOpenDynamic, adLockBatchOptimistic
'rs.Open strsql, cn, adOpenKeyset, adLockReadOnly
rs.Open strsql, cn ', adOpenStatic, adLockBatchOptimistic
Range("A5").CopyFromRecordset rs
存储过程的那个STUFF字段的值就是显示不出来,如果不用那个函数,又可以显示
|
|