GOTO (T-SQL)

When you create “while” in T-SQL, sometimes you need to skip several logics that cannot handled by “continue”. So, you can use “GOTO” to solve above problem. This is an example code to detect odd / even integer input.

[code language=”sql”]
DECLARE @intSampleVariable INT
SET @intSampleVariable = 2

IF ( @intSampleVariable % 2 = 0 )
BEGIN
GOTO evenNumber
END

SELECT ‘Odd’
SELECT ‘this query will skipped’
SELECT ‘created by marifnst’

evenNumber:
BEGIN
SELECT ‘Even’
END
[/code]

I hope this help.

 Marifnst, 2013-08-02

Leave a Reply

Your email address will not be published. Required fields are marked *

Afiseaza emoticoanele Locco.Ro