why my application has worked well for a year but all in sudden stops working with nobody touching it

SQL Server evaluates an expression that depends on cost estimation plan which doesnt always make sense with other programming languages.

declare @a int = 1, @b int = 0
print 'if @a = @b + 1 or @a/@b = 2'
if @a = @b + 1 or @a/@b = 2
print 'No Error'
print 'if @a/@b = 2 or @a = @b + 1'
if @a/@b = 2 or @a = @b + 1
print ' Error'
go

-- we should have got divide by zero error as parent_object_id is 0 but alas NO
select *
from sys.tables
select *
from sys.tables
where schema_id / parent_object_id >10
and object_id < 10

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>