August 4, 2008 at 8:46 am
I have a string, for example,
'CHARLES H#L6CAL JOEL4',
but i need to validate this string. It only may have alphabet letter.
any ideas?
thanks.
August 4, 2008 at 9:00 am
How about a little more information? What do you want to do if the string contains something other than a letter? Such as
report an error
not import the row into a table
replace non-letters with something?
Cheers
ChrisM
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
August 4, 2008 at 9:06 am
Hi, this string only may have alphabet letter, otherwise report an error.
Thanks
August 4, 2008 at 9:16 am
declare @Return varchar(30), @String varchar(30)
set @Return = ''
set @String = 'CHARLES H#L6CAL JOEL4'
SELECT @Return = @Return + SUBSTRING(@String,number,1)
FROM dbo.Numbers WITH (NOLOCK)
WHERE number <= LEN(@String)
AND UPPER(SUBSTRING(@String,number,1)) LIKE '%[^A-Z]%'
SELECT CASE WHEN LEN(@Return) = 0 THEN 'String Ok' else 'Error' End
set @Return = ''
set @String = 'CHARLESHLCALJOEL'
SELECT @Return = @Return + SUBSTRING(@String,number,1)
FROM dbo.Numbers WITH (NOLOCK)
WHERE number <= LEN(@String)
AND UPPER(SUBSTRING(@String,number,1)) LIKE '%[^A-Z]%'
SELECT CASE WHEN LEN(@Return) = 0 THEN 'String Ok' else 'Error' End
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
August 4, 2008 at 9:32 am
OK.THANKS .....
August 4, 2008 at 9:38 am
You're welcome :unsure::ermm:
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
August 4, 2008 at 9:57 am
no need for a numbers table.
declare @t table ( string varchar(255))
insert into @t
select 'CHARLES H#L6CAL JOEL4'
union select 'CHARLESHLCALJOEL'
union select 'red and green'
union select 'RedAndGreen'
union select 'RedAndGreen.'
select string, case when string like '%[^A-Z]%' then 0 else 1 end as zero_if_invalid
from @t
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply