PDA

View Full Version : سوال: جایگزین دستور case برای اکسس



hsn_abieteh
پنج شنبه 03 آذر 1390, 23:41 عصر
سلام
دوستان جایگزین دستور case که برا بانک اس کیو ال میشه ازش استفاده کرد برا access چیه؟
دستور iif فقط بر دو مقدار هست ولی اگه بخوایم برا چندین مقدار شرط بذاریم باید چه کنیم؟

مثلا کد زیر رو چطور میشه با دستور iif نوشت؟


select edu_group = case edu_group when 10100 then 'خودکار' when 10200 then 'مداد' when 10300 then 'پاک کن'end

سعید صابری
جمعه 04 آذر 1390, 09:22 صبح
سوال شما جاش در تالار اکسس هست و با یک جستجوی ساده میتونی به راحتی به جواب برسی


The syntax for the Case statement is:
Select Case test_expression

Case condition_1
result_1
Case condition_2
result_2
...
Case condition_n
result_n

Case Else
result_else

End Select
test_expression is a string or numeric value. It is the value that you are comparing to the list of conditions. (ie: condition_1, condition_2, ... condition_n)
condition_1 to condition_n are evaluated in the order listed. Once a condition is found to be true, the Case statement will execute the corresponding code and not evaluate the conditions any further.
result_1 to result_n is the code that is executed once a condition is found to be true.

Note:
If no condition is met, then the Else portion of the Case statement will be executed. It is important to note that the Else portion is optional.

VBA Code

The Case statement can only be used in VBA code.
Let's take a look at a simple example:
Select Case [Region]
Case "N"
[RegionName] = "North"
Case "S"
[RegionName] = "South"
Case "E"
[RegionName] = "East"
Case "W"
[RegionName] = "West"
End Select

You can also use the To keyword to specify a range of values. For example:
Select Case LNumber
Case 1 To 10
[RegionName] = "North"
Case 11 To 20
[RegionName] = "South"
Case 21 To 30
[RegionName] = "East"
Case Else
[RegionName] = "West"
End Select
You can also comma delimit values. For example:
Select Case LNumber
Case 1, 2
[RegionName] = "North"
Case 3, 4, 5
[RegionName] = "South"
Case 6
[RegionName] = "East"
Case 7, 11
[RegionName] = "West"
End Select
And finally, you can also use the Is keyword to compare values. For example:
Select Case LNumber
Case Is < 100
[RegionName] = "North"
Case Is < 200
[RegionName] = "South"
Case Is < 300
[RegionName] = "East"
Case Else
[RegionName] = "West"
End Select

hsn_abieteh
شنبه 05 آذر 1390, 20:43 عصر
اتفاقا دوست عزیز گشتم ولی چیزی که به دردم بخوره پیدا نشد.
این که شما توضیح دادید که همون case بود که.

متاسفانه وقتی بانک اکسس باشه تو کوئری نمیشه از case استفاده کرد و خطا میده
دوستان کسی می تونه کمک کنه؟