sql server - Why would an Insert statement always fire no matter the results of the preceeding IF statement? -
I am using a SQL Server 2005 database, and I have an I statement that is two different against the same data Behavior is behaving in the set, based on the actions being taken initially ... end block
First of all, if I only want to print on the console, the following code does not print anything, as expected:
if (with 'TBL control Tap select where name = 'SOM_CONTROL_NAME')) starts the end of printed 'control not found' While this code gets print 'control' if desired:
If (exists (choose tap from the tbl control where name = 'SOM_CONTROL_NAME')) print 'Control' is the beginning However, if I change it to a code: if (select tap from the tbl control where name = 'SOM_CONTROL_NAME') exists TblControls values (632, 'NEW_CONTROL_NAME', 'New Control', 1, 1, zero, 1, 'Data Control.', 'Checkbox', Faucet, Zero, 1) End The statewide state is always a fire, even if a match record is present in the tblControls. Is there anything special about the details contained in T-SQL 2005 that can cause this behavior, or Or I'm doing something obvious? I understand that if the logic of the code is false, but when I expected the examination using print statement, it works as expected.
Edit: Generating a "Incorrect Error" message from it.
Any help with this disappointing problem is greatly appreciated.
It has tap in existence .. Choose whether it is confused. Try:
if starting with tblControls values (632 (do not exist (tblControls where name = 'SOME_CONTROL_NAME' is selected from * *), 'NEW_CONTROL_NAME', 'New Control', 1, 1 , In addition, it can be rewritten without parentheses and start / end:
code> Do not exist (select from tblControls * where name = 'SOME_CONTROL_NAME') in tblControls values (include 632, 'NEW_CONTROL_NAME', 'new control', 1, 1, zero, 1, 'DataControls.CheckBox', zero, zero, 1 )
Comments
Post a Comment