Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
IF BEGIN END confusion
Message
 
À
16/06/2008 09:52:18
Jay Johengen
Altamahaw-Ossipee, Caroline du Nord, États-Unis
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01324368
Message ID:
01324386
Vues:
12
>So, both my examples should execute the PRINT if the condition is true? Only the first one is executing. I must have missed something in your logic.

It looks to me like they should execute in both cases if the IF is true, and it should not execute in either case if the IF is false. Something doesn't compute to me..?

>
>>Having the PRINT statement immediately after the IF means that it is what happens if the IF is true. The BEGIN END after the PRINT becomes just a statement block unconnected with the IF.
>>
>>The BEGIN immediately after the IF means that the BEGIN END block happens only if the IF is true - it is directly connected to the IF.
>>
>>
>>>So, the BEGIN is almost like THEN? The lines before the BEGIN always exectute, but those inside the BEGIN only execute if the IF condition is true? If that is the case, then my IF condition must not be true for the behavior I'm seeing.
>>>
>>>>When IF condition is true, the PRINT will be executed in both cases. OTOH, the BEGIN...END block will be executed always in the first case.
>>>>
>>>>
>>>>>The PRINT statement executes:
>>>>>
>>>>>IF @Filename LIKE '%.tiff%'
>>>>>
>>>>>	PRINT @Filename
>>>>>
>>>>>	BEGIN
>>>>>
>>>>>		Some code here
>>>>>
>>>>>	END
>>>>>
>>>>>
>>>>>The PRINT statement does NOT execute:
>>>>>
>>>>>IF @Filename LIKE '%.tiff%'
>>>>>
>>>>>	BEGIN
>>>>>
>>>>>		PRINT @Filename
>>>>>		Some code here
>>>>>
>>>>>	END
>>>>>
>>>>>
>>>>>Why?
____________________________________

Don't Tread on Me

Overthrow the federal government NOW!
____________________________________
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform