|
|
How come code inside a false condition is causing an error
How come code inside a false condition is causing an error?
I have the following code with a condition that is false (lets say 1=2.)
How come I get an error that is related to the code inside if the condition
is false?
Msg 927, Level 14, State 2, Line 3 Database 'NMS' cannot be opened. It is in
the middle of a restore.
The code
IF 1= 2
begin
select * FROM NMS..MR_BackupHistory
end
The error in case it is executed when the db is being restored.
Msg 927, Level 14, State 2, Line 3 Database 'NMS' cannot be opened. It is in
the middle of a restore.
Thanks Avi
|
|
0
|
|
|
|
Reply
|
Avi
|
1/5/2010 3:12:28 PM |
|
Its failing to produce "compile" the plan.
You can use EXEC...
IF 1= 2
begin
exec( 'select * FROM NMS..MR_BackupHistory' )
end
"Avi" <rememberoti@yahoo.com> wrote in message
news:eXvdKlhjKHA.4500@TK2MSFTNGP06.phx.gbl...
> How come code inside a false condition is causing an error?
>
> I have the following code with a condition that is false (lets say 1=2.)
> How come I get an error that is related to the code inside if the
> condition is false?
>
> Msg 927, Level 14, State 2, Line 3 Database 'NMS' cannot be opened. It is
> in the middle of a restore.
>
>
>
> The code
>
> IF 1= 2
>
> begin
>
> select * FROM NMS..MR_BackupHistory
>
> end
>
> The error in case it is executed when the db is being restored.
>
> Msg 927, Level 14, State 2, Line 3 Database 'NMS' cannot be opened. It is
> in the middle of a restore.
>
>
>
> Thanks Avi
>
>
|
|
0
|
|
|
|
Reply
|
Tony
|
1/5/2010 4:03:04 PM
|
|
It still has to parse all the text and create potential plans so it needs to
see the stats for that table.
--
Andrew J. Kelly SQL MVP
Solid Quality Mentors
"Avi" <rememberoti@yahoo.com> wrote in message
news:eXvdKlhjKHA.4500@TK2MSFTNGP06.phx.gbl...
> How come code inside a false condition is causing an error?
>
> I have the following code with a condition that is false (lets say 1=2.)
> How come I get an error that is related to the code inside if the
> condition is false?
>
> Msg 927, Level 14, State 2, Line 3 Database 'NMS' cannot be opened. It is
> in the middle of a restore.
>
>
>
> The code
>
> IF 1= 2
>
> begin
>
> select * FROM NMS..MR_BackupHistory
>
> end
>
> The error in case it is executed when the db is being restored.
>
> Msg 927, Level 14, State 2, Line 3 Database 'NMS' cannot be opened. It is
> in the middle of a restore.
>
>
>
> Thanks Avi
>
>
|
|
0
|
|
|
|
Reply
|
Andrew
|
1/5/2010 4:26:43 PM
|
|
|
2 Replies
188 Views
(page loaded in 0.073 seconds)
|
|
|
|
|
|
|
|
|