Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Trudye
Posting Yak Master
169 Posts |
Posted - 2009-09-27 : 13:19:43
|
| Hi Guys, got a problem.I cannot get this proc to handle dupes. For instance if a user submits two files with the same seq#. Im also having a problem with large gaps in the seq#. As long as its a 1 or 2 number diff it works fine. For instance I tested 1151, 1157, 1160, 1161. I got badk 1153, 1154, 1158, 1159.I am receiving anywhere from 1 to n files daily from several vendors. Each file has a HDR and Trlr. I have managed to validate the Trlr rec but the Hdr is giving me Fits!! Each Hdr contains a seq# and the seq# must be contiguous. Today's hdr seq# must be +1 from yesterday's seq# and all the hdrs recieved today must be contiguous.The problem I am currently experiencing is: I cannot get this proc to handle dupes. For instance if a user submits two files with the same HDR seq#. The proc is not handling the dupe. I am also having a problem with large gaps in the seq#. As long as it is a 1 or 2 number diff between the seq#s it works fine. For instance I read in 4 files with the following seq#s 1151, 1157, 1160, 1161. The proc wrote the following 1153, 1154, 1158, 1159 numbers to my error table.I have placed some sample code below. pls let me know your thoughts. I am a relative novice so I am looking for efficient not complicated but code.Thank you IF OBJECT_ID('My_Seq_Audit','U') IS NULL --Make sure it doesn't exist before trying to create itBEGIN---- CREATE table My_Seq_Audit (Seq_Number int primary key clustered, VendorName varchar(20), Run_Date datetime default getdate(), Vendor_File_Name)CREATE table My_Seq_Audit (Seq_Number int NOT NULL, VendorName varchar(20) NOT NULL, Run_Date datetime default getdate() CONSTRAINT PK_My_Seq_Audit PRIMARY KEY CLUSTERED(Seq_Number, VendorName))ENDDECLARE @run_Date varchar(8)DECLARE @LasT_Seq as intDECLARE @MaxSeq as intset @run_Date = Convert(Varchar(10),Getdate(),112)Print @run_Date-- Provide the Last seq# of the prev run dateSET @LasT_Seq = (SELECT MAX(File_Sequence_No) FROM ZZ.T_HdrWHERE Vendor_Name = 'CCC' AND RunDate <> @run_Date)-- Provide Max Seq# for today's hdrsSET @MAXSeq = (SELECT MAX(File_Sequence_No) FROM ZZ.T_ HdrWHERE Vendor_Name = 'CCC' AND RunDate = @run_Date)print 'initial values CCC'print @LasT_Seq print @MaxSeqWHILE (@LasT_Seq) < @MAXSeqBEGINset @last_seq = @last_seq + 1print 'increment CCC'print @LasT_Seqprint 'File Seq#'SELECT File_Sequence_No FROM ZZ.T_ Hdr WHERE File_Sequence_No = @last_seqIF not exists (SELECT NULL FROM ZZ.T_ Hdr WHERE File_Sequence_No = @last_seq)BEGINInsert My_Seq_Audit (Run_Date, Seq_Number, VendorName)select @run_Date, @last_seq, 'CCC' where not exists (select NULL from My_Seq_Audit where Seq_Number = @Last_Seq)END |
|
|
|
|
|
|
|