Académique Documents
Professionnel Documents
Culture Documents
sql 1
USE [CsgDocs]
GO
/****** Object: StoredProcedure [dbo].[InputFromOldSystem] Script Date: 07/14/2009 17:
29:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[InputFromOldSystem]
/*
HI
This Is where we inport the data from the old datasheet system
PKB
*/
AS
SET NOCOUNT ON
setProdIdEnd:
if (@productGroupId is not null and @productGroupId <> 0 and @productGroupId <>
16)
begin
INSERT INTO DocumentTolookupproductGroup (DocumentId,productGroupId)values
(@DocumentId,isnull(@productGroupId,-1))
end
-- We now need to fill the mamy to many table for the doc to part no
DECLARE PartCURSOR CURSOR FAST_FORWARD FOR
SELECT DISTINCT Lookup.dbo.master_product_list.u_ref, xref.dbo.
datasheet_to_part.part_no
FROM xref.dbo.datasheet_to_part RIGHT OUTER JOIN
Lookup.dbo.master_product_list ON Lookup.dbo.
master_product_list.part_no = xref.dbo.datasheet_to_part.part_no
WHERE ( xref.dbo.datasheet_to_part.datasheet_id = @OldDataSheetId)
OPEN PartCURSOR
FETCH PartCURSOR INTO @masterProductlistId,@part_no
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO DocumentToLookupMasterProductList (DocumentId,
masterProductlistId)values(@DocumentId,@masterProductlistId)
if ISDATE(@DateReleased)=1
begin
set @RevisionDate = convert(varchar(20),@DateReleased,101) -- set date into dd/
mm/yyyy
end
else
begin
set @DateReleased = convert(varchar(20),getdate(),101) -- set date into dd/mm/
yyyy
set @RevisionDate = convert(varchar(20),getdate(),101) -- set date into dd/mm/
yyyy
end
-- We now need to update the samplesystem table with the new datasheet id
-- in order to stop us changing a number that we have already changed I have
add a X to the replace string
if isnull(@OldDataSheetId,-1) > -1
begin
DECLARE SampleOrdersCURSOR CURSOR FAST_FORWARD FOR
SELECT data_sheet_refs,Order_No
FROM samplesystem.dbo.Orders
WHERE (data_sheet_refs LIKE '%'+cast(@OldDataSheetId as varchar
(20))+',%')
OPEN SampleOrdersCURSOR
FETCH SampleOrdersCURSOR INTO @data_sheet_refs,@OrderNo
WHILE @@FETCH_STATUS = 0
BEGIN
set @tempdata_sheet_refs = replace(replace(','+cast(@
data_sheet_refs as varchar(20)) , ','+cast(@OldDataSheetId as varchar(20))+',' , ',X'+
cast(@DownloadFileId as varchar(20))+',' ) , ','+cast(@OldDataSheetId as varchar(20))+'
,' , ',X'+cast(@DownloadFileId as varchar(20))+',' )
update samplesystem.dbo.Orders set data_sheet_refs = substring(@
tempdata_sheet_refs,2,len(@tempdata_sheet_refs)) where Order_No = @OrderNo
FETCH SampleOrdersCURSOR INTO @data_sheet_refs,@OrderNo
END
CLOSE SampleOrdersCURSOR
DEALLOCATE SampleOrdersCURSOR
end
set @OldTitle = @Title
FETCH xCURSOR INTO @Title,@Description,@DocumentTypeId,@SiteCase,@OldLookupLanguageId,
@DateReleased,@FileLocation,@salesZoneId,@MarketGroupId,@
productGroupId,@OldDataSheetId
--print (@OldTitle +' = '+ @Title )
if (@OldTitle = @Title and @@FETCH_STATUS = 0) goto fileLoop -- loop back for each file
COMMIT TRANSACTION
END
CLOSE xCURSOR
DEALLOCATE xCURSOR
-- in order to stop us changing a number we add a X to the replace string
-- now we need to remove this X
update samplesystem.dbo.Orders set data_sheet_refs = replace(data_sheet_refs ,'X','') where
data_sheet_refs LIKE '%X%'
--- if we get here! I am either lucky or clever !!!!!!!!!
RETURN
C:\Documents and Settings\eb010275\Local Settings\Temp\~vs128.sql 1
USE [CsgDocs]
GO
/****** Object: StoredProcedure [dbo].[InputFromOldSystem_1_CleanUp] Script Date: 07/14
/2009 17:29:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[InputFromOldSystem_1_CleanUp]
/*
HI
This Is where we inport the data from the old datasheet system
PKB
*/
AS
SET NOCOUNT ON
This Is where we inport the data from the old datasheet system
PKB
*/
AS
SET NOCOUNT ON
OPEN xCURSOR --
FETCH xCURSOR INTO @Title,@Description,@DocumentTypeId,@UserGroupCase,@
OldLookupLanguageId,
@DateReleased,@FileLocation,@salesZoneId,@MarketGroupId,@
productGroupId,@OldDataSheetId
C:\Documents and Settings\eb010275\Local Settings\Temp\~vs12F.sql 2
WHILE @@FETCH_STATUS = 0
BEGIN
-- BEGIN TRANSACTION -- this is for the commits for each row in the old datasheet
table + records so if it fails it rolls back and we don't get a part up load !!!
-- We now need to fill the mamy to many table for the doc to part no
DECLARE PartCURSOR CURSOR FAST_FORWARD FOR
SELECT DISTINCT Lookup.dbo.master_product_list.u_ref
FROM xref.dbo.datasheet_to_part RIGHT OUTER JOIN
Lookup.dbo.master_product_list ON Lookup.dbo.
master_product_list.part_no LIKE xref.dbo.datasheet_to_part.part_no
WHERE ( xref.dbo.datasheet_to_part.datasheet_id = @OldDataSheetId)
OPEN PartCURSOR
FETCH PartCURSOR INTO @masterProductlistId
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO DocumentToLookupMasterProductList (DocumentId,
masterProductlistId)values(@DocumentId,@masterProductlistId)
-- We now need to update the samplesystem table with the new datasheet id
-- in order to stop us changing a number that we have already changed I have
add a X to the replace string
fileLoop:
-- get the ID from the Ref
select @LookupLanguageId = (Select ID from lookup.dbo.Languages where Language_ref = @
OldLookupLanguageId)
if ISDATE(@DateReleased)=1
begin
set @RevisionDate = convert(varchar(20),@DateReleased,101) -- set date into dd/
mm/yyyy
end
else
begin
set @DateReleased = convert(varchar(20),getdate(),101) -- set date into dd/mm/
yyyy
set @RevisionDate = convert(varchar(20),getdate(),101) -- set date into dd/mm/
yyyy
end
C:\Documents and Settings\eb010275\Local Settings\Temp\~vs12F.sql 3
set @FileLocation = replace(lower(@FileLocation),'/resources','')
print (@DocumentId)
exec InsertDownloadFile @DocumentId,@LookupLanguageId,@DateReleased,@RevisionDate,@
FileLocation,@FileSizeInKb,'','','',@DownloadFileId out
exec InsertDownloadFileToDocumentStore @DownloadFileId,1
-- add the new data sheet id into the old data sheet table
update xref.dbo.datasheet_to_part set new_id = @DownloadFileId where datasheet_id = @
OldDataSheetId
END
CLOSE xCURSOR
DEALLOCATE xCURSOR
-- in order to stop us changing a number we add a X to the replace string
-- now we need to remove this X
update samplesystem.dbo.Orders set data_sheet_refs = replace(data_sheet_refs ,'X','') where
data_sheet_refs LIKE '%X%'
-- swop the coums around in the datasheet_to_part table and remove the new_id col
--exec InputFromOldSystem_3_swopColumsInDataSheetToPart
return
C:\Documents and Settings\eb010275\Local Settings\Temp\~vs133.sql 1
USE [CsgDocs]
GO
/****** Object: StoredProcedure [dbo].[InputFromOldSystem_3_swopColumsInDataSheetToPart]
Script Date: 07/14/2009 17:29:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[InputFromOldSystem_3_swopColumsInDataSheetToPart]
/*
HI
we take the data from the new_id colum and put into the datasheet_id col
and remove the new_id colum
PKB
*/
AS
BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
BEGIN TRANSACTION
CREATE TABLE dbo.Tmp_datasheet_to_part
(
datasheet_id int NOT NULL,
part_no varchar(501) NOT NULL
) ON [PRIMARY]
IF EXISTS(SELECT * FROM dbo.datasheet_to_part)
EXEC('INSERT INTO dbo.Tmp_datasheet_to_part (datasheet_id, part_no)
SELECT distinct datasheet_id, new_id FROM dbo.datasheet_to_part (HOLDLOCK TABLOCKX)
')
DROP TABLE dbo.datasheet_to_part
EXECUTE sp_rename N'dbo.Tmp_datasheet_to_part', N'datasheet_to_part', 'OBJECT'
ALTER TABLE dbo.datasheet_to_part ADD CONSTRAINT
PK_datasheet_to_part PRIMARY KEY CLUSTERED
(
datasheet_id,
part_no
) ON [PRIMARY]
GRANT SELECT ON dbo.datasheet_to_part TO Xrefread AS dbo
GRANT REFERENCES ON dbo.datasheet_to_part TO Xrefupd AS dbo
GRANT SELECT ON dbo.datasheet_to_part TO Xrefupd AS dbo
GRANT UPDATE ON dbo.datasheet_to_part TO Xrefupd AS dbo
GRANT INSERT ON dbo.datasheet_to_part TO Xrefupd AS dbo
GRANT DELETE ON dbo.datasheet_to_part TO Xrefupd AS dbo
COMMIT
-- cleaning done lets start to walk the old datasheet table