The following bits of code are allowing too long of strings to be entered. The entries are being truncated before going into the table and will go into the table, but only if the trucated value is correct. (i.e. 1211 is too long, but is truncated to 12 which is legitimate.) Any way it’s looked at, it is still wrong.
My code should be catching the length issue and giving me an error message, but it is not. Is this a matter that would be corrected with the Trans/Commit/Rollback code?
I have verified in my tables the length and type of the fields.
Thanks.
Bill
My code should be catching the length issue and giving me an error message, but it is not. Is this a matter that would be corrected with the Trans/Commit/Rollback code?
I have verified in my tables the length and type of the fields.
Thanks.
Bill
Code:
--validate that the customer number exists in the parameter (not
--NULL or empty. Can be a length of 1, 2 or 3.
if @CustomerNumber is null or datalength(Ltrim(@CustomerNumber)) = 0
begin
set @Message = 'Customer Number Required'
set @Continue = 0
end
--then check its length
if datalength(cast(@CustomerNumber as varchar (3))) < 1 or
datalength(cast(@CustomerNumber as varchar (3))) > 3
begin
set @Message = 'Wrong Length of Customer Number'
set @Continue = 0
end
--validate the job number
if @JobNumber is null or datalength(Ltrim(@JobNumber)) = 0
begin
set @Message = 'Job Number Required'
set @Continue = 0
end
--then check its length. MUST BE 4, include leading 0, i.e. 0786
if datalength(cast(@JobNumber as varchar (4))) <> 4
begin
set @Message = 'Wrong Length of Job Number'
set @Continue = 0
end
--validate the Step number
if @StepNumber is null or datalength(Ltrim(@StepNumber)) = 0
begin
set @Message = 'Step Number Required'
set @Continue = 0
end
--then check its length. MUST BE 2, include leading 0, i.e. 07
if datalength(cast(@StepNumber as varchar (2))) <> 2
begin
set @Message = 'Wrong Length of Step Number'
set @Continue = 0
end
--validate Location
if @LocationNumber is null or datalength(Ltrim(@LocationNumber)) = 0
begin
set @Message = 'Location Number Required'
set @Continue = 0
end
--then check its length. Can be 1 or 2.
if datalength(cast(@LocationNumber as varchar (2))) < 1 or
datalength(cast(@LocationNumber as varchar (2))) > 2