我有这个代码:
DECLARE
@CustomerID int = 8,
@UtilityCompanyID int = 1
SELECT MD.SERV_ACCT,
AD.ACCOUNT,
MD.SERV_ADDRESS
----AD.DOING_BUSINESS_AS,
--MD.SERV_ACCT + ', ' + AD.ACCOUNT + ', ' + MD.SERV_ADDRESS AS ADB
FROM
(SELECT DISTINCT SERV_ACCT, SERV_ADDRESS, MAX(INV_DATE) as MAXINVDATE
FROM tblAPSData
WHERE SERV_ACCT NOT IN (SELECT ServiceAccount
FROM tblMEP_Meters
JOIN tblMEP_Sites
ON tblMEP_Meters.SiteID = tblMEP_Sites.ID
JOIN tblMEP_Projects
ON tblMEP_Projects.ID = tblMEP_Sites.ProjectID
WHERE CustomerID = 8
AND Type = 1
)
AND ACCOUNT IN (SELECT AccountNumber
FROM tblMEP_CustomerAccounts
WHERE CustomerID = @CustomerID
AND UtilityCompanyID = @UtilityCompanyID)
AND INV_DATE > DATEADD(month, -6, getdate())
GROUP BY SERV_ACCT, SERV_ADDRESS) MD
join tblAPSdata AD on MD.SERV_ACCT = AD.SERV_ACCT
and MD.MAXINVDATE = AD.INV_DATE
这是输出:
SERV_ACCT ACCOUNT SERV_ADDRESS
0289S61288 117512280 921 N dsdijdsi
1435S01282 117512280 238 D dsdijads
2498S21288 117512280 23814 4fksf
5538S21284 117512280 4324 fjsdf
6109S12286 117512280 0912 fuehsf
7488S22289 117512280 242 fsjdhfs
8058S12287 117512280 309 fjsnef
9058S00288 117512280 342 fhsfuqq
9645S21281 117512280 556 dajdjawd
1440S13289 312937281 2383 hfsdufh
5384S92284 979437282 324 dhauda
0492S90281 117512280 29349 dhsadfsf
1303S90280 117512280 89e3y djasd
1548S00286 117512280 3426 iodjad
7358S00281 117512280 39844 jdfasjf
9168S00282 117512280 399 ndfsfjk
我想要以 HTML 格式的输出!那可能吗?有谁知道 SQL Server 是否可以做到这一点?还是我必须手动编码?我读到了字符串分隔符,但我不确定这是否是我真正想做的,因为我什至不知道该怎么做。