1

Topic: Procedure performance in IF... ELSE

Wrote such procedure, transferring to parameter in which a title of a certain database it is possible to import only to it the data
Procedure:
[spoiler]

CREATE PROCEDURE [dbo]. [p_import] @DB_MSSQL nvarchar (20), @PK nvarchar (20), @From nvarchar (10)
AS
BEGIN
-- If the basis of the client outswapping only on it is fulfilled is specified
IF @DB_MSSQL = ' GT'
BEGIN
-- If the specific office outswapping only on it is fulfilled is specified
IF @PK = ' F'
BEGIN
EXEC [SECURE_DB]. [dbo]. [p_importing_F];
END
ELSE
BEGIN
IF @PK = ' Y'
BEGIN
EXEC [SECURE_DB]. [dbo]. [p_importing_Y];
END
ELSE
BEGIN
IF @PK = ' A'
BEGIN
EXEC [SECURE_DB]. [dbo]. [p_importing_A];
END
ELSE
BEGIN
IF @PK = ' V'
BEGIN
EXEC [SECURE_DB]. [dbo]. [p_importing_V];
END
ELSE
BEGIN
...
END
END
END
END
END

[/spoiler]
When fulfilled its call

EXEC [SECURE_DB]. [dbo]. [p_importing_advertising] ' GT ', ' Y ', NULL

That it did not stop on unit Y, and continued to be fulfilled and for unit A, V.?, without end
To work procedure of the beginnings normally only after adding RETURN
[spoiler]

CREATE PROCEDURE [dbo]. [p_import] @DB_MSSQL nvarchar (20), @PK nvarchar (20), @From nvarchar (10)
AS
BEGIN
-- If the basis of the client outswapping only on it is fulfilled is specified
IF @DB_MSSQL = ' GT'
BEGIN
-- If the specific office outswapping only on it is fulfilled is specified
IF @PK = ' F'
BEGIN
EXEC [SECURE_DB]. [dbo]. [p_importing_F];
END
ELSE
BEGIN
IF @PK = ' Y'
BEGIN
EXEC [SECURE_DB]. [dbo]. [p_importing_Y];
RETURN
END
ELSE
BEGIN
IF @PK = ' A'
BEGIN
EXEC [SECURE_DB]. [dbo]. [p_importing_A];
END
ELSE
BEGIN
IF @PK = ' V'
BEGIN
EXEC [SECURE_DB]. [dbo]. [p_importing_V];
END
ELSE
BEGIN
...
END
END
END
END
END

[/spoiler]
Explain please, why procedure performance [SECURE_DB]. [dbo]. [p_importing_Y] in procedure [SECURE_DB]. [dbo]. [p_import] did not stop, though it was exact (at my subjective view:)) it is specified in performance and termination conditions?

2

Re: Procedure performance in IF... ELSE

I.e. you walked procedure or though stuck print in a debugger... In key points?
For sounds improbably.
. Recently at  too if worked crookedly... But guilty there was I - begin crookedly placed.

3

Re: Procedure performance in IF... ELSE

Especially, in the resulted example it is not necessary any begin and any end

4

Re: Procedure performance in IF... ELSE

iap wrote:

Especially, in the resulted example it is not necessary any begin and any end

Without begin and end there is an error in syntax if performance of two procedures sequentially in the unit is specified

5

Re: Procedure performance in IF... ELSE

hulk77 wrote:

Explain please, why procedure performance [SECURE_DB]. [dbo]. [p_importing_Y] in procedure [SECURE_DB]. [dbo]. [p_import] did not stop

Whence you know, what at you is fulfilled? Prints are not present.
At you also should not stop, should unit IF @PK = ' V ' will be fulfilled... ELSE
Besides, look at a typical error - correct procedure in one basis, cause in another

6

Re: Procedure performance in IF... ELSE

hulk77 wrote:

Without begin and end there is an error in syntax if performance of two procedures sequentially in the unit

At you is specified there is no "a performance of two procedures sequentially in the unit"
Or you show "the theoretical" code?
All is "theoretically correct, simple  your code.

7

Re: Procedure performance in IF... ELSE

alexeyvg, thanks

8

Re: Procedure performance in IF... ELSE

ms sql allows to form a procedure name dynamic:

declare @proc_name nvarchar (250) = ' SECURE_DB.dbo.p_importing _ ' + @PK
EXEC @proc_name

Also it is not necessary all these if-else