June 29, 2012 at 8:40 pm
I'm trying to convert an old script I had in Access but running into Case When problems. I just starting and I'm not sure why I'm getting a swiggly red line under the = sign. I'm just starting so a lot of the code is messed up but I'm right now just trying to figure out why I getting the red line under the first "When" statement.
Sorry if it all seems messy.
Declare @cString as Varchar(100)
Set @cString = 'David H. Rogers Age 56'
Declare @x as int
Declare @str1 as Varchar(100)
Declare @chkStr as Varchar(100)
Declare @DataPattern as Varchar(100)
Set @x = 1
Set @chkStr = ''
Set @str1 = ''
Set @DataPattern = 1
--If IsVoid(@cString) Then
-- Set @DataPattern = Null
-- Exit Function
--End If
--For @x = 1 To Len(@cString)
Select
Case
When (SubString(@cString, @x, 1)) Between 97 and 122 Then @str1 = 'L'
When (SubString(@cString, @x, 1)) Between 48 and 57 Then @str1 = 'N'
When (SubString(@cString, @x, 1)) = 39 Then @str1 = 'A'
When (SubString(@cString, @x, 1)) = 44 Then @str1 = 'M'
When (SubString(@cString, @x, 1)) = 46 Then @str1 = 'P'
When (SubString(@cString, @x, 1)) Between 0 and 31 Then @str1 = 'O'
When (SubString(@cString, @x, 1)) Between 33 and 38 Then @str1 = 'O'
When (SubString(@cString, @x, 1)) Between 40 and 43 Then @str1 = 'O'
When (SubString(@cString, @x, 1)) = 47 Then @str1 = 'O'
When (SubString(@cString, @x, 1)) Between 58 and 64 Then @str1 = 'O'
When (SubString(@cString, @x, 1)) Between 91 and 96 Then @str1 = 'O'
When (SubString(@cString, @x, 1)) > 122 Then @str1 = 'O'
When (SubString(@cString, @x, 1)) = 32 Then @str1 = 'S'
When (SubString(@cString, @x, 1)) Between 65 and 90 Then @str1 = 'U'
End
If @str1 = 'U' Or str1 = 'L' Then
str1 = 'C'
End
If @chkStr = @str1 And (@str1 = 'C' Or @str1 = 'N') Then
chkStr = str1
Else
DataPattern = DataPattern & str1
@chkStr = @str1
End
Next @x
End Function
June 30, 2012 at 2:24 am
try this approach
SELECT @str1 = CASE
WHEN ( Substring(@cString, @x, 1) ) BETWEEN 97 AND 122
THEN 'L'
WHEN ( Substring(@cString, @x, 1) ) BETWEEN 48 AND 57
THEN 'N'
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
June 30, 2012 at 1:56 pm
Works, thanks.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply