on 02-06-2014 3:37 PM
Hi.
Code:
IF @object_type = '18' AND @transaction_type = 'A'
BEGIN
DECLARE @numeroDoc int
DECLARE @CodPn nvarchar(50)
DECLARE @Serial int
SELECT @numeroDoc = CONVERT(int,@list_of_cols_val_tab_del)
SELECT @CodPn = OPCH.CardCode, @Serial = OPCH.Serial FROM OPCH WHERE OPCH.DocEntry = @numeroDoc
SELECT @COUNT_PCH = COUNT(1) FROM OPCH WHERE serial = @Serial and cardcode = @CodPn
IF @COUNT_PCH > 0
BEGIN
SELECT @error = 1,
@error_message = 'FAILED'
END
END
Hi Bruno,
You did not say what you meant by not working.
Your code :
SELECT @COUNT_PCH = COUNT(1) FROM OPCH WHERE serial = @Serial and cardcode = @CodPn
IF @COUNT_PCH > 0
BEGIN
SELECT @error = 1,
@error_message = 'FAILED'
END
Should always return you @COUNT_PCH > 0.
Means each time you add, you will be stopped by this SP.
Your newly added record will be available in the table already when you do the select.
Hence your @COUNT will at least 1.
If you want to block duplicate entry you should either check @COUNT_PCH>1 or
add 'DocEntry <> @numeroDoc' in your where clause.
Regards
Edy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In the query do not observe the DECLARE @ COUNT_PCH of.
You can test the results of the consultation to see the problem,
comment "if @ COUNT_PCH> 0" to always define an error.
And the error message says @ error_message = 'FAILED' + convert (varchar, @ Serial) + ',' + Convert (varchar, @ COUNT_PCH).
Thus the message you know the value of variables to make decisions.
I could not do the test because they do not define it as a value to the serial
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
103 | |
12 | |
11 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.