DECLARE@ColumnName NVARCHAR(100)SET@ColumnName='总数'+ CAST(DATEPART(HOUR, GETDATE())AS NVARCHAR)+'点前派单'DECLARE@Sql NVARCHAR(MAX)SET@Sql='SELECT COUNT(1) AS '+ QUOTENAME(@ColumnName)+'
FROM MBHZJ_GD
WHERE "SN码" IS NULL AND CAST(boss归档时间 AS date) LIKE ''2023-12-21%'''EXEC sp_executesql @SqlDECLARE@ColumnName NVARCHAR(100)SET@ColumnName='总数'+ CAST(DATEPART(HOUR, GETDATE())AS NVARCHAR)+'点前派单'DECLARE@DateFilter NVARCHAR(20)SET@DateFilter=CONVERT(NVARCHAR(10), GETDATE()-1,23)+'%'DECLARE@Sql NVARCHAR(MAX)SET@Sql='SELECT COUNT(1) AS '+ QUOTENAME(@ColumnName)+'
FROM MBHZJ_GD
WHERE "SN码" IS NULL AND CAST(boss归档时间 AS DATE) LIKE '+ QUOTENAME(@DateFilter,'''')EXEC sp_executesql @Sql