0

我使用下面的查询得到了正确的输出Oracle

SELECT COUNT(*) AS CNT FROM MSS WHERE TRIM(UPPER(FIRSTNAME)|| UPPER(SECONDNAME)) LIKE UPPER('qw1')||UPPER('121212')

但是我需要查询MS SQL Server,任何帮助将不胜感激..

4

2 回答 2

0

尝试

SELECT COUNT(*) AS CNT FROM MSS WHERE LTRIM(RTRIM(UPPER(FIRSTNAME) + UPPER(SECONDNAME))) LIKE UPPER('qw1') + UPPER('121212')

但我不确定你是否不需要比较任何包含你类似条件的东西:

SELECT COUNT(*) AS CNT FROM MSS WHERE LTRIM(RTRIM(UPPER(FIRSTNAME) + UPPER(SECONDNAME))) LIKE '%' + UPPER('qw1') + UPPER('121212') + '%'

否则,您可以=在第一个查询中使用:

SELECT COUNT(*) AS CNT FROM MSS WHERE LTRIM(RTRIM(UPPER(FIRSTNAME) + UPPER(SECONDNAME))) = UPPER('qw1') + UPPER('121212')
于 2013-09-30T11:11:32.577 回答
0

1.创建表 MSS 时,确保名称(排序规则)上不区分大小写,并确保使用 varchar 或 nvarchar 作为名称。

例子:

CREATE TABLE MSS
(
firstname nvarchar(50) collate Latin1_General_CI_AS,
lastname nvarchar(50) collate Latin1_General_CI_AS
)

2.填充表 MSS 时确保名称前没有空格。

例子:

declare @val1 nvarchar(50) = ' qw1 '
declare @val2 nvarchar(50) = ' 121212 '
insert MSS(firstname, lastname)
values(ltrim(@val1), ltrim(@val2))

3.进行更新查询以修复当前数据,因此名称不以空格开头。

例子:

UPDATE MSS
SET FIRSTNAME = LTRIM(FIRSTNAME),
SECONDNAME = LTRIM(SECONDNAME)
WHERE FIRSTNAME <> LTRIM(FIRSTNAME)
or SECONDNAME <> LTRIM(SECONDNAME)

4.写下你的查询。

例子:

SELECT COUNT(*) AS CNT 
FROM MSS
WHERE FIRSTNAME like 'qw1'
and SECONDNAME like '121212'

请在比较之前停止连接列,这会降低性能

于 2013-09-30T11:28:08.493 回答