我想获取特定日期输入的所有记录,例如今天:
ALTER PROCEDURE [dbo].[SP_GET_QUEUESINFO_BY_DATE]
@date nvarchar = '2012-09-21'
AS
BEGIN
declare @dateStart nvarchar(50) = @date + ' 00:00:00.0'
declare @dateEnd nvarchar(50) = @date + ' 23:59:59.437';
declare @returnData table (allQueue int,inQueue int,outQueue int)
SELECT 'table1' as table_name, COUNT(*)
FROM Queue as Counts
UNION ALL
SELECT 'table2' as table_name,COUNT(*) FROM Queue as Counts
WHERE QueueDate BETWEEN @dateStart AND @dateEnd
AND QueueNumIn != 0
END
编辑: 我现在编辑了我的代码:
ALTER PROCEDURE [dbo].[SP_GET_QUEUESINFO_BY_DATE]
AS
BEGIN
declare @date2 datetime
set @date2= '2012-09-21'
SELECT 'AllQueue' as table_name, COUNT(*)
FROM Queue as sdfds
UNION ALL
SELECT 'InQueue' as table_name,COUNT(*)
FROM Queue as sdfds
WHERE QueueDate >=@date2
AND QueueNumIn != 0
UNION ALL
SELECT 'OutQueue' as table_name, COUNT(*) FROM Queue as sdfds
WHERE QueueDate >=@date2
AND QueueNumOut != 0
END
它返回三个记录:
一个问题是第二列没有名称。为什么?另外,我只想返回一条包含三行的记录,而不是包含 2 个字段的 3 条单独记录。