0

我正在寻找最好的表结构来创建如下所示的动态 SQL 语句(它还不是动态的)。我必须在两者之间做出选择

  1. 连接表
  2. 包含所有列的单行,内容以逗号分隔,然后我将对其进行解析
  3. 一个大表,每个成本中心活动代码多行
  4. 或其他任何东西

在此示例中,所有链接到的键是:“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

任何建议都会受到欢迎。谢谢

4

0 回答 0