Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
funketekun
Constraint Violating Yak Guru
491 Posts |
Posted - 2006-11-30 : 11:29:37
|
| i just want one row instead of multiple rows results.declare @name varchar(30)declare @count intdeclare @a intset @name = 'dennis dennis'set @count = 0set @a = 1while(@count < len(@name))beginselect count(substring(@name, @a, 1)), substring(@name, @a, 1)where substring(@name, @a, 1) = 'd'select @count = @count +1select @a = @a+1end |
|
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2006-11-30 : 11:35:10
|
| [code]declare @name varchar(30)declare @count intdeclare @a intdeclare @dcount intset @name = 'dennis dennis'set @dcount = 0set @count = 0set @a = 1while(@count < len(@name))beginselect @dcount = @dcount + count(substring(@name, @a, 1))where substring(@name, @a, 1) = 'd'select @count = @count +1select @a = @a+1endselect @dcount[/code] |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2006-11-30 : 11:39:50
|
| or this:declare @name varchar(30)set @name = 'dennis dennis'select len(@name) - len(replace(@name,'d','')) as CountOfDBe One with the OptimizerTG |
 |
|
|
funketekun
Constraint Violating Yak Guru
491 Posts |
Posted - 2006-11-30 : 11:46:49
|
| excellent thanks. |
 |
|
|
|
|
|