select len(Col1)-len(replace([Col1]),',','') from tablename
select len(col)-len(replace(col,',',''))+1 from tb
select len(col)-len(replace(col,',','')) from tb;
---------------------------------------------------------------- -- Author :fredrickhu(我是小F,向高手学习) -- Date :2010-01-25 11:04:59 -- Version: -- Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86) -- Nov 24 2008 13:01:59 -- Copyright (c) 1988-2005 Microsoft Corporation -- Developer Edition on Windows NT 5.2 (Build 3790: Service Pack 1) -- ---------------------------------------------------------------- --> 测试数据:[tb] if object_id('[tb]') is not null drop table [tb] go create table [tb]([col] varchar(9)) insert [tb] select '1' union all select '1,2' union all select '1,22,3,33' --------------开始查询-------------------------- select len(col)-len(replace(col,',','')) from [tb] ----------------结果---------------------------- /* ----------- 0 1 3(3 行受影响 */
select len(col)-len(replace(col,',','')) from tb
select len(Col1)-len(replace([Col1],',','')) from tablename
len(col)-len(replace(col,',',''))+1
from tb
-- Author :fredrickhu(我是小F,向高手学习)
-- Date :2010-01-25 11:04:59
-- Version:
-- Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86)
-- Nov 24 2008 13:01:59
-- Copyright (c) 1988-2005 Microsoft Corporation
-- Developer Edition on Windows NT 5.2 (Build 3790: Service Pack 1)
--
----------------------------------------------------------------
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([col] varchar(9))
insert [tb]
select '1' union all
select '1,2' union all
select '1,22,3,33'
--------------开始查询--------------------------
select len(col)-len(replace(col,',','')) from [tb]
----------------结果----------------------------
/* -----------
0
1
3(3 行受影响
*/
len(col)-len(replace(col,',',''))
from tb