我想从数据库中获取数据。但是他们说发生了语法错误。
这是代码
lsCmd = "SELECT * FROM"
lsCmd &= "(SELECT DISTINCT userid, status, DATEPART(dd, [date]) as Date"
lsCmd &= "FROM edrsDB..tbl_status"
lsCmd &= "Union"
lsCmd &= "SELECT DISTINCT userid, status, DATEPART(DD,[date]) as Date"
lsCmd &= "FROM edrsDB..tbl_public_holiday"
lsCmd &= "Union ALL"
lsCmd &= "SELECT DISTINCT userid, status, DATEPART(DD,[Date]) as Date "
lsCmd &= "FROM edrsDB..tbl_station_weekend"
lsCmd &= "WHERE DatePart(MM, [Date]) = 3"
lsCmd &= "And DATEPART(YYYY, [date]) = 2017"
lsCmd &= "And date IS NOT NULL) AS monthlyRpt"
lsCmd &= "PIVOT (MAX(status)"
lsCmd &= "FOR userid IN (XSP, BSR, BPT, XPW, IPH, XTH, TGG, XKG, XKM, XLG, KBR, KUA, LGK,MKZ, PEN, XGM, JHB, XBN, STW, TIN, MUA)) AS pivottable"
他们说这个
{“获取错误:'edrsDB'附近的语法不正确。”}
答案 0 :(得分:0)
这是我在每个lscmd ="
lsCmd = "SELECT * FROM"
lsCmd &= " (SELECT DISTINCT userid, status, DATEPART(dd, [date]) as Date"
lsCmd &= " FROM edrsDB..tbl_status"
lsCmd &= " Union"
lsCmd &= " SELECT DISTINCT userid, status, DATEPART(DD,[date]) as Date"
lsCmd &= " FROM edrsDB..tbl_public_holiday"
lsCmd &= " Union ALL"
lsCmd &= " SELECT DISTINCT userid, status, DATEPART(DD,[Date]) as Date "
lsCmd &= " FROM edrsDB..tbl_station_weekend"
lsCmd &= " WHERE DatePart(MM, [Date]) = 3"
lsCmd &= " And DATEPART(YYYY, [date]) = 2017"
lsCmd &= " And date IS NOT NULL) AS monthlyRpt"
lsCmd &= " PIVOT (MAX(status)"
lsCmd &= " FOR userid IN (XSP, BSR, BPT, XPW, IPH, XTH, TGG, XKG, XKM, XLG, KBR, KUA, LGK,MKZ, PEN, XGM, JHB, XBN, STW, TIN, MUA)) AS pivottable"