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
 SQL Server Development (2000)
 Remove Underscores from string

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-05-09 : 08:26:48
Ruth Mifsud writes "Hi,
I will really appreciate any help on this!!

I need to randomly generate a series of characters and I must ensure that the string created does not contain any underscores.

I am using NEWID() method to generate the string.
Do I need to check for underscores? Or does it never return any? If yes how do I remove them (since underscore is a wild character)? I am using the following sql which is eating up all my string!!!

DECLARE @myid uniqueidentifier
SET @myid = NEWID()

Declare @i int
DECLARE @b varchar(50)

set @b = CONVERT(varchar(255), @myid)
print @b

select @i = patindex('%_%', @b)
while @i > 0
begin
select @i = patindex('%_%', @b)
select @b = replace(@b,substring(@b, @i, 1),'')
print @b
end

Thanks a lot for your help!
Ruth Mifsud"

mr_mist
Grunnio

1870 Posts

Posted - 2005-05-09 : 08:56:06
NEWID will not generate underscores. It will, however, generate dashes. It is a fixed format value of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx where all the xs are hexadecimal characters (0-9, a-f)

-------
Moo. :)
Go to Top of Page
   

- Advertisement -