1

Transactions在 SQL Server 表中有一个列A

我在该表中有大约 1000 行,并且在每一行中我都有字符串,这些字符串具有

 "@transaction --space of 3 characters---1" or "@transaction --space of 3 characters---0" these strings may be even repeated n number of times within the single row.

结果 - 我想检查所有

"@transaction --space of 3 characters---1"  ones how many times repeated.
"@transaction --space of 3 characters---0"  zeros how many times repeated.

我尝试了诸如

Select * from A where transaction like '%@transaction --space of 3 characters---1%
Select * from A where transaction like '%@transaction --space of 3 characters---0%

但是这些不能给我想要的结果,因为单列中可能有更多的上述字符串。

谁能建议如何分别计算以 1 和 0 结尾的所有这两个字符串?

提前致谢

4

1 回答 1

1

尝试这个

SELECT count (*) as [Count], 'Strings with 1' as [Comment]
FROM A 
WHERE transaction like cast (@transaction as varchar(50)) +'???1%'

UNION ALL

SELECT count (*) as [Count], 'Strings with 0'
FROM A 
WHERE transaction like cast (@transaction as varchar(50)) +'???0%'
于 2013-06-05T11:58:43.823 回答