ITPub博客

首页 > Linux操作系统 > Linux操作系统 > SQLServer无法判断空格数量

SQLServer无法判断空格数量

原创 Linux操作系统 作者:seteor 时间:2009-05-26 11:30:49 0 删除 编辑

DROP TABLE [dbo].[TestTable]
CREATE TABLE [dbo].[TestTable](
 [Id] [int] NOT NULL,
 [Name] [char](5) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
 CONSTRAINT [PK_TestTable] PRIMARY KEY CLUSTERED
(
 [Id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

insert into TestTable(id, [Name]) values (1, '')
insert into TestTable(id, [Name]) values (2, ' ')
insert into TestTable(id, [Name]) values (3, '     ')

select id, 'XX' + [Name] + 'YY' from TestTable where [Name] = ''
select id, 'XX' + [Name] + 'YY' from TestTable where [Name] = ' '
select id, 'XX' + [Name] + 'YY' from TestTable where [Name] = '     '

exec sp_executesql N'SELECT * FROM [dbo].[TestTable] WHERE ([Name] <> @Name1 )',N'@Name1 char(1)',@Name1=' '
exec sp_executesql N'SELECT * FROM [dbo].[TestTable] WHERE ([Name] <> @Name1 )',N'@Name1 char(8000)',@Name1=' '
exec sp_executesql N'SELECT * FROM [dbo].[TestTable] WHERE ([Name] <> @Name1 )',N'@Name1 varchar(1)',@Name1='   '

exec sp_executesql N'SELECT * FROM [dbo].[TestTable] WHERE ([Name] = @Name1 )',N'@Name1 char(8000)',@Name1=' '
exec sp_executesql N'SELECT * FROM [dbo].[TestTable] WHERE ([Name] = @Name1 )',N'@Name1 char(1)',@Name1=' '
exec sp_executesql N'SELECT * FROM [dbo].[TestTable] WHERE ([Name] = @Name1 )',N'@Name1 varchar(5)',@Name1='  '

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/618537/viewspace-604183/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2008-10-31

  • 博文量
    25
  • 访问量
    52285