all groups > sql server programming > november 2004 >
You're in the

sql server programming

group:

how to make case sensitive query


how to make case sensitive query Suresh
11/28/2004 11:15:06 PM
sql server programming:
I need to retrive the a case sensitive value from a string.
like select All_Capital_Alphebets("This Is My String")
Expected result : "TIMS" (ie all capital letters from the string.

How can i achieve this.

Thanks in advance

Re: how to make case sensitive query Uri Dimant
11/29/2004 9:18:28 AM
Suresh
There are some examples
create table ABCD
(
[id]smallint not null,
description varchar(20) null
)
insert into ABCD([id],description)values (1,'DFh2AcZ')
insert into ABCD([id],description)values (2,'dHZ3')

)

SELECT description FROM ABCD where charindex(cast('H' as
varbinary(20)),cast(description as varbinary(20)))> 0

SELECT description
FROM ABCD
WHERE description ='dhZ3'COLLATE Latin1_General_BIN

SELECT description
FROM ABCD
WHERE charindex('h',description COLLATE Latin1_General_BIN)>0





[quoted text, click to view]

Re: how to make case sensitive query Uri Dimant
11/29/2004 10:04:17 AM
Suresh
It seems that I did not understand your requirements
Here is another one written by Itzik Ben-Gan

CREATE FUNCTION dbo.fn_capitalize
(
@str AS nvarchar(100)
)
RETURNS nvarchar(100)
AS
BEGIN

DECLARE
@ret_str AS varchar(100),
@pos AS int,
@len AS int

SELECT
@ret_str = N' ' + LOWER(@str),
@pos = 1,
@len = LEN(@str) + 1

WHILE @pos > 0 AND @pos < @len
BEGIN
SET @ret_str = STUFF(@ret_str,
@pos + 1,
1,
UPPER(SUBSTRING(@ret_str,@pos + 1, 1)))
SET @pos = CHARINDEX(N' ', @ret_str, @pos + 1)
END

RETURN RIGHT(@ret_str, @len - 1)

END



[quoted text, click to view]

Re: how to make case sensitive query avnrao
11/29/2004 1:21:27 PM
Create Function All_Capital_Letters(@Sentence nvarchar(4000))

returns nvarchar(4000)

begin

declare @Len int, @index Int,

@output nvarchar(4000)

set @output = ''

Set @Len = Len(@Sentence)

SET @index = 0

while(@index < @Len)

begin

if cast(upper(substring(@Sentence,@index,1)) as varbinary(20)) =
cast(substring(@Sentence,@index,1) as varbinary(20))

begin

SET @output = @output +
upper(substring(@Sentence,@index,1))

end

SET @index = @index + 1

end

return @output

end



hope this helps..

Av.

http://dotnetjunkies.com/WebLog/avnrao
http://www28.brinkster.com/avdotnet



[quoted text, click to view]

RE: how to make case sensitive query Huiyong Lau
11/29/2004 2:43:07 PM
Here's the code that will return all the CAP letters. Enjoy!

create function dbo.All_Capital_Letters(@text nvarchar(4000))
returns nvarchar(4000)
begin
declare @result nvarchar(4000), @tmp_char char(1), @cnt int
select @cnt = 1, @result = ''

while @cnt < len(@text)
begin
set @tmp_char = substring(@text, @cnt, 1)
if ascii(@tmp_char) between 65 and 90 set @result = @result +
@tmp_char
set @cnt = @cnt + 1
end

return @result
end

Regards,
Huiyong

[quoted text, click to view]
AddThis Social Bookmark Button