Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

if digit is 1 Or 4 Or 7 Or 0

Posted on 2011-02-10
17
Medium Priority
?
239 Views
Last Modified: 2012-05-11
I am trying the query below but it doesn't work. Can't remember how to do this.

something like this??
If intRDigit = In(1,4,7,0) Then

If intRDigit = 1 Or 4 Or 7 Or 0 Then
strtest = "A"
ElseIf intRDigit = 2 Or 5 Or 8 Then
strtest = "B"
Else
strtest = "C"
End If
0
Comment
Question by:Shawn
  • 6
  • 5
  • 4
  • +1
17 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 2000 total points
ID: 34867445
If intRDigit = 1 Or intRDigit = 4 Or intRDigit = 7 Or intRDigit = 0 Then
strtest = "A"
ElseIf intRDigit = 2 Or intRDigit = 5 Or intRDigit = 8 Then
strtest = "B"
Else
strtest = "C"
End If
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34867455
You can also use this

If InStr(intRDigit, "1470") > 0 Then
    strtest = "A"
ElseIf InStr(intRDigit, "258") > 0 Then
    strtest = "B"
Else
    strtest = "C"
End If

Open in new window

0
 
LVL 96

Expert Comment

by:Lee W, MVP
ID: 34867459
Or you could use Select Case -

SELECT CASE IntRDigit
   Case 1,4,7,0
      strtest = "A"
   Case 2, 5, 8
      strtest = "B"
   Case Else
      strtest = "C"
End Select
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34867465
Or use SELECT CASE

Select Case intRDigit
Case 1, 4, 7, 0
    strtest = "A"
Case 2, 5, 8
    strtest = "B"
Case Else
    strtest = "C"
End Select

Open in new window

0
 
LVL 1

Author Closing Comment

by:Shawn
ID: 34867498
brilliant. thank you for the choice :)

Shawn
0
 
LVL 75
ID: 34867504
One Line:

strtest = Choose(strtest + 1, "A", "A", "B", "C", "A", "B", "C", "A", "B")

mx
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34867545
@Dbmx

This is both shorter, and correct, as long as intRDigit is >= 0
Your Choose options don't cover more than 0-8.

strtest = Left(Mid("AABCABCAB", intRDigit + 1, 1) + "C", 1)
0
 
LVL 1

Author Comment

by:Shawn
ID: 34867565
i actually used the select case.
the digits are 0-9. the else covers 3, 6 and 9.
0
 
LVL 1

Author Comment

by:Shawn
ID: 34867575
the actual strings are quite bit longer than strtest = "A".
0
 
LVL 75
ID: 34867578
"Your Choose options don't cover more than 0-8."
Either does your Accepted solution  - so what?

And your new solution uses two functions instead of 1 !

mx
0
 
LVL 96

Expert Comment

by:Lee W, MVP
ID: 34867593
> i actually used the select case.
So then why wasn't there at least a split?  I posted the select case option...
0
 
LVL 75
ID: 34867597
"Either does your Accepted solution  - so what?"
Never mind ... I see that it does.  
0
 
LVL 75
ID: 34867603
" I posted the select case option..."
Exactly ... First at that ...

mx
0
 
LVL 75
ID: 34867615
Still one line ... covering any number > 8:

strtest = Nz(Choose(strtest + 1, "A", "A", "B", "C", "A", "B", "C", "A", "B"), "C")

mx
0
 
LVL 1

Author Comment

by:Shawn
ID: 34867650
leew
>>So then why wasn't there at least a split?
originally I just tested them and gave out the points to the first correct answer.
afterwards I decided which one to use. sorry about that. If you really want I can see if I can't reopen to distribute the points.
0
 
LVL 75
ID: 34867667
Just a suggestion ... sometimes it's best to wait for a few posts, especially when it's clear there will be many possible solutions, some simpler than others :-)

mx
0
 
LVL 1

Author Comment

by:Shawn
ID: 34867676
good point. thx :)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question