我正在寻找最好的表结构来创建如下所示的动态SQL语句(它还不是动态的)。我必须在
之间做出选择在此示例中,所有链接的密钥为:'NSEA8102',这是一个成本中心活动代码
SELECT
@pDate,
@pDate,
'NSEA8102', --Cost Centre Activity Code
ccg.tCCGroup,
SUM(logs.tTripHours) AS tTriphours,
'Actual EMV Hours Worked - ' + DATENAME(MONTH,@pDATE) + ' ' + CAST(YEAR(@pDate) AS CHAR(4))
FROM dbo.tblEMV_Logsheet AS logs INNER JOIN
dbo.tblLookup_EMVEquipment AS ccg ON logs.tEquipmentKey = ccg.tEquipmentKey
WHERE tDate BETWEEN @BMonth and @EMonth
AND (logs.tAreaCode in ('MINEE', 'SERVICE'))
AND (logs.tEventCode LIKE 'RASSTEEPS')
AND logs.tSourceLocationCode = 'STEEPS'
AND logs.tDestinationLocationCode = 'ERASSTSP'
AND (ccg.tCCGroup IN ('FADT', 'FPC800', 'FWA800'))
AND ccg.tValid = 1
GROUP BY ccg.tCCGroup
欢迎提出任何建议。感谢