資料欄位型別匹配
/*
--==========================================================================================
-- Generated By: Changyong Jiang
-- Create Date: 2013/03/25
-- Description: 返回取得的DataInconsistency Alert的資料
-- Generated By: Changyong Jiang
-- Create Date: 2013/05/24
-- Description:修改時間由原來的獲取上本週的資料,改為獲取昨天的資料
-- Generated By: Changyong Jiang
-- Create Date: 2013/06/05
-- Description: data dump dumpload order by
--==========================================================================================
CREATE PROCEDURE [dbo].[Alt_Read_ROHSDataDUMP_SP]
@TransType VARCHAR(100) = '',
@UserName VARCHAR(100) = '',
@ProgramName VARCHAR(MAX) = '',
@Owner VARCHAR(MAX) = '',
@strdate VARCHAR(10) = null,
@DataType VARCHAR(20)='',
@PageIndex INT=1,
@PageSize INT=20
AS
SET NOCOUNT ON
--SET TRANSACTION ISOLATION LEVEL READ COMMITTED
DECLARE @_RowCount INT
DECLARE @_PageCount INT
DECLARE @_StartRow INT
CREATE TABLE #Temp(
Iden BIGINT IDENTITY(1, 1),
[DataType] VARCHAR(30),
[FileName] VARCHAR(200),
[FilePath] VARCHAR(2000),
[CreatedDate] varchar(10)
)
CREATE TABLE #newTemp(
[DataType] VARCHAR(30),
[FileName] VARCHAR(200),
[FilePath] VARCHAR(2000),
[CreatedDate] varchar(10)
)
set @strdate=convert(varchar(10),@strdate,120)
--SELECT convert(varchar(10),GETDATE(),120)
--SET @strdate='2013-05-08'
IF @strdate IS NULL
BEGIN
IF @TransType = 'ROHSDATADUMP_ALERT'
OR @TransType = 'ROHSDATADUMP_DOWNLOAD'
BEGIN
SET @strdate = convert(varchar(10),DATEADD(DAY,-1, GETDATE()),120)
END
END
IF @TransType='ROHSDATADUMP_ALERT'
BEGIN
--解決前臺傳入多個owner
DECLARE @TempOwner TABLE (_Owner VARCHAR(30))
DECLARE @TempProgramName TABLE (_ProgramName VARCHAR(30))
INSERT INTO @TempOwner
(
_Owner
)
SELECT adapt_object FROM [dbo].[StringToArray](@Owner,',')
INSERT INTO @TempProgramName
(
_ProgramName
)
SELECT adapt_object FROM [dbo].[StringToArray](@ProgramName,',')
SELECT
rh.[MPasite] AS [MPa site],
rh.[Program] AS [Program],
rh.[SKU] AS [SKU],
rh.[BOM_Level] AS [BOM Level],
rh.[HPPN] AS [HP PN],
rh.[Description] AS [Description],
rh.[Material_Group] AS [Material Group],
rh.[Control_Code] AS [Control Code],
rh.[Mat_Type] AS [Mat_Type],
rh.[Make2Buy] AS [Make/Buy],
rh.[MFGR] AS [MFGR],
rh.[MPN] AS [MPN],
rh.[Lowest_RoHS_ID] AS [Lowest_RoHS_ID],
rh.[Highest_RoHS_ID] AS [Highest_RoHS_ID],
rh.[Last_Upload_Date] AS [Last Upload Date],
rh.[Change_By] AS [Change By] ,
rh.[SDoC] AS [SDoC] ,
rh.[G_template] AS [G-template]
FROM RoHSDataDump_History_BomTree(NOLOCK) rh
--WHERE CONVERT(varchar(10),rh.[strDate])=@strdate
WHERE rh.[strDate]=@strdate
AND rh.[MPasite] in (SELECT _Owner FROM @TempOwner)
and rh.[Program] in (SELECT _ProgramName FROM @TempProgramName)
ORDER BY rh.[MPasite],rh.[Program],rh.[SKU],rh.[intShowNo]
END
IF @TransType='ROHSDATADUMP_DOWNLOAD'
begin
DECLARE @_ControlValue nvarchar(100) SET @_ControlValue='2'
Declare @_QueryValue varchar(100) set @_QueryValue='8'
DECLARE @maxcount int set @maxcount=0
DECLARE @maxdate nvarchar(10)
select @_ControlValue=ControlValue from ADControlValueM WHERE
ControlName='ROHSDATA_FILE' and CustomField1='DOWNLOADVALIDWEEKS'
select @_QueryValue=ControlValue from ADControlValueM WHERE
ControlName='ROHSDATA_FILE' and CustomField1='ProgramQueryReportTimes'
declare @_topnum int
set @_topnum=CONVERT(int ,@_QueryValue)
truncate table #Temp
INSERT INTO #Temp
select
a.[DataType] as [DataType],
a.[FileName] as [FileName],
a.[FilePath] as [FilePath],
Convert(varchar(10),a.[CreatedDate],103) as [CreatedDate]
from
(
select
ddlu.[DataType] as [DataType],
ddlu.[FileName] as [FileName],
ddlu.[FilePath] as [FilePath],
ddlu.[CreatedDate] as [CreatedDate]
from DataDownLoadURL ddlu
where ddlu.[username] =@UserName
and ddlu.[CreatedDate] between DATEADD(week, -CONVERT (INT ,@_ControlValue),
CONVERT(DATETIME,getdate())) and CONVERT(DATETIME,getdate())
and ddlu.[DataType]='ROHSDATADUMP'
union
select Top (@_topnum)
ddlu.[DataType] as [DataType],
ddlu.[FileName] as [FileName],
ddlu.[FilePath] as [FilePath],
ddlu.[CreatedDate] as [CreatedDate]
from DataDownLoadURL ddlu
where ddlu.[username] =@UserName
and ddlu.[DataType]='ROHSPROGRAMQUERYREPORT'
order by ddlu.[CreatedDate] desc
) a
order by
--a.[DataType] asc,
a.[CreatedDate] DESC
SELECT @maxcount=COUNT(1) FROM #Temp
IF (@maxcount<=0)
BEGIN
select @maxdate=Convert(nvarchar(10),max([CreatedDate]),121) from DataDownLoadURL --獲取表中最大的資料,顯示其中最最後的2周資料
truncate table #newTemp
INSERT INTO #newTemp
select
ddlu.[DataType] as [DataType],
ddlu.[FileName] as [FileName],
ddlu.[FilePath] as [FilePath],
Convert(varchar(10),ddlu.[CreatedDate],103)as [CreatedDate]
from DataDownLoadURL ddlu
where ddlu.[username] =@UserName Or (@UserName is null )
and ddlu.[CreatedDate] between DATEADD(week, -2,CONVERT(DATETIME,@maxdate)) and CONVERT(DATETIME,@maxdate)
and ddlu.[DataType]=@DataType
order by
--ddlu.[DataType] asc,
ddlu.[CreatedDate] DESC
INSERT INTO #Temp SELECT *FROM #newTemp
END
SELECT @_RowCount = COUNT(1) FROM #Temp
SET @PageIndex = @PageIndex - 1
IF @PageSize = 0
SET @PageSize = @_RowCount
IF @_RowCount > 0
BEGIN
IF @_RowCount % @PageSize > 0
SET @_PageCount = @_RowCount / @PageSize + 1
ELSE
SET @_PageCount = @_RowCount / @PageSize
SET @_StartRow = @PageSize * @PageIndex + 1
END
ELSE
BEGIN
SET @_PageCount = 0
SET @_StartRow = 0
END
SELECT TOP(@PageSize) * FROM #Temp WHERE Iden >= @_StartRow
SELECT @_PageCount AS TotalPages
DROP TABLE #Temp
DROP TABLE #newTemp
end
IF @TransType='ROHSDATADUMP_PARA'
BEGIN
SELECT a.ControlValue,a.CustomField1
from ADControlValueM a (Nolock)
WHERE ControlName='ROHSDATA_FILE' order by a.SeqNo
END
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24867586/viewspace-763792/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Java資料型別與資料庫欄位型別對應關係Java資料型別資料庫
- 資料庫中欄位資料型別以及約束資料庫資料型別
- 欄位管理,為什麼只有新增的時候才自動匹配欄位型別型別
- PHP 操作 mysql blob 資料型別的欄位PHPMySql資料型別
- SQL中欄位比較型別不匹配錯誤:‘cannot be cast to’SQL型別AST
- ORANCLE 資料已存在,修改欄位型別長度型別
- MongoDB更改欄位型別MongoDB型別
- SqlSugar code first 欄位為列舉型別,預設生成資料庫欄位為bigint如何設定為int型別SqlSugar型別資料庫
- sql語句修改欄位型別和增加欄位SQL型別
- ES Mapping ,1 欄位型別APP型別
- MySQL欄位型別最全解析MySql型別
- mssql sqlserver 可以儲存二進位制資料的欄位型別詳解SQLServer型別
- 查詢mysql某張表中的所有資料(欄位)型別MySql型別
- 支援 enum 型別的欄位允許為空插入資料庫型別資料庫
- 【mongo】mongo 欄位型別互轉Go型別
- MySQL欄位新增註釋,但不改變欄位的型別MySql型別
- [提問交流]建立模型,新增屬性,欄位型別如何設定2位小數的欄位型別模型型別
- 將list型別對映到資料欄位 @TableField(typeHandler = StringListTypeHandler.class)型別
- yii2 從資料庫獲取內容值型別與資料庫欄位型別問題解決資料庫型別
- mysql表操作(alter)/mysql欄位型別MySql型別
- Oracle 修改欄位型別和長度Oracle型別
- java基本資料型別佔位Java資料型別
- 用Elasticsearch做大規模資料的多欄位、多型別索引檢索Elasticsearch多型型別索引
- MySQL中TEXT與BLOB欄位型別的區別MySql型別
- JSON欄位型別在ORM中的使用JSON型別ORM
- 為什麼資料庫表的int型別欄位對映到實體類中要使用Integer型別,而不是int型別?...資料庫型別
- 【clickhouse專欄】基礎資料型別說明資料型別
- 如何檢視型別為LRAW的SAP ABAP資料庫表欄位的內容型別資料庫
- 模型資料追加欄位模型
- 多型關聯自定義的型別欄位的處理多型型別
- 【MybatisPlus】資料庫的datetime型別欄位為空的時候,報錯空指標?MyBatis資料庫型別指標
- MySQL VARCHAR型別欄位到底可以定義多長MySql型別
- js資料型別之基本資料型別和引用資料型別JS資料型別
- java之二進位制與資料型別Java資料型別
- 資料型別: 資料型別有哪些?資料型別
- SAP CDS view 如何將 CHAR 型別的資料欄位和當前系統日期比較View型別
- 關於mysql中欄位定義的型別int、tinyint區別MySql型別
- SAP WM中階儲存型別裡的Full stk rmvl 欄位和Return Storage type欄位型別
- java查詢資料庫,int型欄位為null的情況Java資料庫Null