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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Case Sensitive CHARINDEX???

Author  Topic 

wgpubs
Yak Posting Veteran

67 Posts

Posted - 2004-06-14 : 18:26:36
Is there a way to do it?

Basically want to use the CHARINDEX function in a case-sensitive way.

eg. SELECT CHARINDEX( 'b' , 'abdf' ) = 2 but SELECT CHARINDEX ( 'B' , 'abdf' ) = 0

Thanks - wg

nr
SQLTeam MVY

12543 Posts

Posted - 2004-06-14 : 18:41:10
declare @i int, @j int
select @i = 0, @j = 0
while @i <> 1 and @j <> 1
begin
select @i = @i + 1
select @i = charindex('b',@str,@i)
If @i <> 0
begin
if convert(binary(1),substring(@str,@i,1)) = convert(binary(1),'b')
select @j = 1
end
select @i = @i + 1
end
select case when @j = 1 then 'found' else 'not found' end


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2004-06-14 : 18:41:56
[code]SELECT CHARINDEX ( convert(varbinary,'b') , convert(varbinary,'abdf') )
SELECT CHARINDEX ( convert(varbinary,'B') , convert(varbinary,'abdf') )[/code]
Go to Top of Page

wgpubs
Yak Posting Veteran

67 Posts

Posted - 2004-06-14 : 19:01:01
cool thanks. I thought about this before but wasn't sure it would work cuz of the binary conversion. - wg

quote:
Originally posted by ehorn

SELECT CHARINDEX ( convert(varbinary,'b') , convert(varbinary,'abdf') )
SELECT CHARINDEX ( convert(varbinary,'B') , convert(varbinary,'abdf') )


Go to Top of Page
   

- Advertisement -