ITPUB论坛 » MS SQL Server » SQL查询参数怪异问题
新一届的微软MVP评选已经开始,欢迎各位推荐!
2008-7-1 18:20 bigholy
SQL查询参数怪异问题

执行以下步骤后:
create table demo
( t1 int not null default 0)

-- execute 5 times
insert into demo
select 0

--
set statistics profile on
select * from demo where t1 = ''
set statistics profile off

返回的结果如下:
0
0
0
0
0

5        1        SELECT * FROM [demo] WHERE [t1]=@1        14
5        1          |--Table Scan(OBJECT:([Northwind].[dbo].[demo]), WHERE:([demo].[t1]=Convert([@1])))        14

为何在条件语句中指定了t1='',也能返回结果,请问是哪里出了错误?
请大家帮分析一下,谢谢!

2008-7-2 00:02 kalonggood
我猜隐性把''转成了0

2008-7-2 12:17 allys1116
*** 作者被禁止或删除 内容自动屏蔽 ***

2008-7-2 12:17 allys1116
*** 作者被禁止或删除 内容自动屏蔽 ***

页: [1]
查看完整版本: SQL查询参数怪异问题


Powered by ITPUB论坛