-- Description: 按月查询数据
-- =============================================
ALTER PROCEDURE [dbo].[DataCsvs_QueryDoMethod]
@I_Sender NVARCHAR(200)='', --客户端执行按钮
@I_ReturnMessage NVARCHAR(MAX)='' OUTPUT, --返回的信息,支持多语言
@I_ExceptionFieldName NVARCHAR(100)='' OUTPUT, --向客户端报告引起冲突的字段
@I_LanguageId CHAR(1)='1', --客户端传入的语言ID
@I_PlugInCommand VARCHAR(5)='', --插件命令
@I_OrBitUserId CHAR(12)='', --用户ID
@I_OrBitUserName NVARCHAR(100)='', --用户名
@I_ResourceId CHAR(12)='', --资源ID(如果资源不在资源清单中,那么它将是空的)
@I_ResourceName nvarchar(100)='', --资源名
@I_PKid char(12) ='', --主键
@I_ParentPKId char(12)='', --父级主键
@I_Parameter nvarchar(100)='', --插件参数
--以上变量为系统服务固定接口参数,必须在每一个DoEvent过程中实现.
@HostCoordinate NVARCHAR(50)='',
@HostName NVARCHAR(50)='',
@StartDate datetime=null,
@EndDate datetime=NULL,
@Mouth NVARCHAR(50)='',
@Year NVARCHAR(50)=''
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
DECLARE @Sql NVARCHAR(MAX)
DECLARE @tablename NVARCHAR(MAX)
-- DECLARE @firstday DATETIME
--DECLARE @lastday DATETIME
--SET @firstday=CONVERT(VARCHAR(10),DATEADD(DAY,-DATEPART(DAY,GETDATE())+1,GETDATE()),23) +' 00:00:00' --当月第一天
--SET @lastday=CONVERT(VARCHAR(10),DATEADD(DAY,-1,DATEADD(MONTH,1,GETDATE()-DAY(GETDATE())+1)),23)+' 23:59:59' --当月最后一天
-- 检查查询条件
IF @HostName = '' AND @HostCoordinate = '' AND @StartDate IS NULL AND @EndDate IS NULL
BEGIN
SET @I_ReturnMessage = 'ServerMessage:请选择查询条件:设备品牌/设备产线/开始日期/结束日期!'
RETURN -1
end
--产线不能为空
IF ISNULL(@HostCoordinate,'')=''
BEGIN
SET @I_ReturnMessage = 'ServerMessage:请选择设备产线!'
RETURN -1
end
--日期不能为空
IF ISNULL(@Mouth,'')=''
BEGIN
SET @I_ReturnMessage = 'ServerMessage:请选择需要查询几月的数据!'
RETURN -1
end
--查询1月数据
IF @Mouth='01'
BEGIN
SET @Mouth='01'
SET @Year=cast(datepart(year,GETDATE()) as nvarchar(50))
SET @tablename='DataCsv'+@Year+@Mouth
SET @Sql='SELECT * FROM '+@tablename+' ORDER BY DetectionTime ASC'
--SET @Sql='SELECT * FROM '+@tablename+' WHERE DetectionTime BETWEEN '''+CONVERT(VARCHAR(30),@firstday,21)+''' AND '''+CONVERT(VARCHAR(30),@lastday,21)+''' ORDER BY DetectionTime ASC'
EXEC (@Sql)
END
--查询2月数据
IF @Mouth='02'
BEGIN
SET @Mouth='02'
SET @Year=cast(datepart(year,GETDATE()) as nvarchar(50))
SET @tablename='DataCsv'+@Year+@Mouth
SET @Sql='SELECT * FROM '+@tablename+' ORDER BY DetectionTime ASC'
EXEC (@Sql)
END
--查询3月数据
IF @Mouth='03'
BEGIN
SET @Mouth='03'
SET @Year=cast(datepart(year,GETDATE()) as nvarchar(50))
SET @tablename='DataCsv'+@Year+@Mouth
SET @Sql='SELECT * FROM '+@tablename+' ORDER BY DetectionTime ASC'
EXEC (@Sql)
END
--查询4月数据
IF @Mouth='04'
BEGIN
SET @Mouth='04'
SET @Year=cast(datepart(year,GETDATE()) as nvarchar(50))
SET @tablename='DataCsv'+@Year+@Mouth
SET @Sql='SELECT * FROM '+@tablename+' ORDER BY DetectionTime ASC'
EXEC (@Sql)
END
--查询6月数据
IF @Mouth='05'
BEGIN
SET @Mouth='05'
SET @Year=cast(datepart(year,GETDATE()) as nvarchar(50))
SET @tablename='DataCsv'+@Year+@Mouth
SET @Sql='SELECT * FROM '+@tablename+' ORDER BY DetectionTime ASC'
EXEC (@Sql)
END
--查询6月数据
IF @Mouth='06'
BEGIN
SET @Mouth='06'
SET @Year=cast(datepart(year,GETDATE()) as nvarchar(50))
SET @tablename='DataCsv'+@Year+@Mouth
SET @Sql='SELECT * FROM '+@tablename+' ORDER BY DetectionTime ASC'
EXEC (@Sql)
END
--查询7月数据
IF @Mouth='07'
BEGIN
SET @Mouth='07'
SET @Year=cast(datepart(year,GETDATE()) as nvarchar(50))
SET @tablename='DataCsv'+@Year+@Mouth
SET @Sql='SELECT * FROM '+@tablename+' ORDER BY DetectionTime ASC'
EXEC (@Sql)
END
--查询8月数据
IF @Mouth='08'
BEGIN
SET @Mouth='08'
SET @Year=cast(datepart(year,GETDATE()) as nvarchar(50))
SET @tablename='DataCsv'+@Year+@Mouth
SET @Sql='SELECT * FROM '+@tablename+' ORDER BY DetectionTime ASC'
EXEC (@Sql)
END
--查询9月数据
IF @Mouth='09'
BEGIN
SET @Mouth='09'
SET @Year=cast(datepart(year,GETDATE()) as nvarchar(50))
SET @tablename='DataCsv'+@Year+@Mouth
SET @Sql='SELECT * FROM '+@tablename+' ORDER BY DetectionTime ASC'
EXEC (@Sql)
END
---查询10月数据
IF @Mouth='10'
BEGIN
SET @Mouth='10'
SET @Year=cast(datepart(year,GETDATE()) as nvarchar(50))
SET @tablename='DataCsv'+@Year+@Mouth
SET @Sql='SELECT * FROM '+@tablename+' ORDER BY DetectionTime ASC'
EXEC (@Sql)
END
---查询11月数据
IF @Mouth='11'
BEGIN
SET @Mouth='11'
SET @Year=cast(datepart(year,GETDATE()) as nvarchar(50))
SET @tablename='DataCsv'+@Year+@Mouth
SET @Sql='SELECT * FROM '+@tablename+' ORDER BY DetectionTime ASC'
EXEC (@Sql)
END
---查询12月数据
IF @Mouth='12'
BEGIN
SET @Mouth='12'
SET @Year=cast(datepart(year,GETDATE()) as nvarchar(50))
SET @tablename='DataCsv'+@Year+@Mouth
SET @Sql='SELECT * FROM '+@tablename+' ORDER BY DetectionTime ASC'
EXEC (@Sql)
END
END