473,385 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

I need help with an IF statement

I currently have a column in a query that is called result codes. These result codes are either 45,80,30 etc.. What I am trying to do is since I have the query that runs I built a report and it show the result code fine but I want to have it covert the result code to text that I specify.

Example if result code = 30 I want it to say "Not Interested" instead of showing 30

Can someone guide me in the right direction?

Thank you
Aug 10 '10 #1

✓ answered by dsatino

A select case is easy in itself, but if you have no prior experience you're a long way away from returning results so lets stick with the SQL.

The UNION query does affect performance noticeably at high levels of detail, but when you UNION aggregate queries it's usually still very fast. Your UNION will look like this:

SELECT CallHist.ResultCode,Switch([callhist.resultcode]=5,"Cancel After Card Declined",[callhist.resultcode]=6,"Card Declined Sent Admin",[callhist.resultcode]=7,"Spanish Speaker",[callhist.resultcode]=30,"Answering Machine",[callhist.resultcode]=31,"Abandoned by Agent",[callhist.resultcode]=45,"Not Now",[callhist.resultcode]=69,"Verified Number") as resulttext, Count(CallHist.ResultCode) AS CountOfResultCode, CallHist.UserID, CallHist.QueueNo, Count(CallHist.QueueNo) AS CountOfQueueNo
FROM CallHist
WHERE CallHist.CallDT>=[Enter Start date] And CallHist.CallDT<=[Enter End Date] And CallHist.ResultCode<70
GROUP BY CallHist.ResultCodeSwitch([callhist.resultcode]=5,"Cancel After Card Declined",[callhist.resultcode]=6,"Card Declined Sent Admin",[callhist.resultcode]=7,"Spanish Speaker",[callhist.resultcode]=30,"Answering Machine",[callhist.resultcode]=31,"Abandoned by Agent",[callhist.resultcode]=45,"Not Now",[callhist.resultcode]=69,"Verified Number"),CallHist.UserID, CallHist.QueueNo
ORDER BY CallHist.ResultCode
UNION
SELECT CallHist.ResultCode,Switch([callhist.resultcode]=71,"No Contact",[callhist.resultcode]=72,"Wrong Number",[callhist.resultcode]=73,"Not Interested",[callhist.resultcode]=75,"Callback",[callhist.resultcode]=77,"Change Number",[callhist.resultcode]=80,"Sale",[callhist.resultcode]=85,"Sale New Customer",[callhist.resultcode]=982,"Automated Busy",[callhist.resultcode]=983,"Automated No Answer",[callhist.resultcode]=984,"Automated Telco",[callhist.resultcode]=988,"Automated Abandoned",[callhist.resultcode]=990,"Automated No Dial",[callhist.resultcode]=991,"Automated Fax",[callhist.resultcode]=993,"Automated Dropped Call",[callhist.resultcode]=994,"Automated Dial Failed") as resulttext, Count(CallHist.ResultCode) AS CountOfResultCode, CallHist.UserID, CallHist.QueueNo, Count(CallHist.QueueNo) AS CountOfQueueNo
FROM CallHist
WHERE CallHist.CallDT>=[Enter Start date] And CallHist.CallDT<=[Enter End Date] And CallHist.ResultCode>=70
GROUP BY CallHist.ResultCode,Switch([callhist.resultcode]=71,"No Contact",[callhist.resultcode]=72,"Wrong Number",[callhist.resultcode]=73,"Not Interested",[callhist.resultcode]=75,"Callback",[callhist.resultcode]=77,"Change Number",[callhist.resultcode]=80,"Sale",[callhist.resultcode]=85,"Sale New Customer",[callhist.resultcode]=982,"Automated Busy",[callhist.resultcode]=983,"Automated No Answer",[callhist.resultcode]=984,"Automated Telco",[callhist.resultcode]=988,"Automated Abandoned",[callhist.resultcode]=990,"Automated No Dial",[callhist.resultcode]=991,"Automated Fax",[callhist.resultcode]=993,"Automated Dropped Call",[callhist.resultcode]=994,"Automated Dial Failed"),CallHist.UserID, CallHist.QueueNo
ORDER BY CallHist.ResultCode;

11 1620
Hi mate.
It is depend on how many codes would you like "translate" to text, and how many different text you want to show.

Personally, I would have created the table with codes and and this table to query.

CodeId | Description
------------------------
30 | Not inserted
80 | Not inserted
45 | Not inserted

Regards
cureben
Aug 10 '10 #2
dsatino
393 256MB
If you're evaluating this in an access query, use a Switch() that will look like this

Switch([yourfield]=30,"Not Interested",[yourfield]=80,"Your text",[yourfield]=45,"Other Text",......)

If you're using VBA, use a Select Case that looks like this
Expand|Select|Wrap|Line Numbers
  1. Public Function YourFx() as string
  2. Dim x as Integer (or proper type)
  3. x=[yourfield]
  4.  
  5. Select Case x
  6.    Case 30
  7.      YourFx="Not interested"
  8.    Case 80
  9.      YourFx="Other text"
  10.    etc....
  11. End Select
  12. end function
  13.  
The Switch can hold a lot, but it does cap at some point. I think the Select Case can be infinite
Aug 10 '10 #3
@ dsatino
Thank you everyone for the help this is what I have

SELECT CallHist.ResultCode, Count(CallHist.ResultCode) AS CountOfResultCode, CallHist.UserID, CallHist.QueueNo, Count(CallHist.QueueNo) AS CountOfQueueNo
FROM CallHist
WHERE (((CallHist.CallDT)>=[Enter Start date] And (CallHist.CallDT)<=[Enter End Date]))
GROUP BY CallHist.ResultCode, CallHist.UserID, CallHist.QueueNo
ORDER BY CallHist.ResultCode;

Where would I put the switch and how?
Aug 10 '10 #4
dsatino
393 256MB
SELECT CallHist.ResultCode,Switch([callhist.resultcode]=...) as resulttext, Count(CallHist.ResultCode) AS CountOfResultCode, CallHist.UserID, CallHist.QueueNo, Count(CallHist.QueueNo) AS CountOfQueueNo
FROM CallHist
WHERE (((CallHist.CallDT)>=[Enter Start date] And (CallHist.CallDT)<=[Enter End Date]))
GROUP BY CallHist.ResultCode,Switch([callhist.resultcode]=...), CallHist.UserID, CallHist.QueueNo
ORDER BY CallHist.ResultCode;
Aug 10 '10 #5
@dsatino

You ROCK!!! It worked. Just what I was looking for. Thank you.
Aug 10 '10 #6
@dsatino

So I think it might be a problem with the amount of result codes. I am getting an error saying it is too complex.

This is what I have now.

SELECT CallHist.ResultCode,Switch([callhist.resultcode]=5,"Cancel After Card Declined",[callhist.resultcode]=6,"Card Declined Sent Admin",[callhist.resultcode]=7,"Spanish Speaker",[callhist.resultcode]=30,"Answering Machine",[callhist.resultcode]=31,"Abandoned by Agent",[callhist.resultcode]=45,"Not Now",[callhist.resultcode]=69,"Verified Number",[callhist.resultcode]=71,"No Contact",[callhist.resultcode]=72,"Wrong Number",[callhist.resultcode]=73,"Not Interested",[callhist.resultcode]=75,"Callback",[callhist.resultcode]=77,"Change Number",[callhist.resultcode]=80,"Sale",[callhist.resultcode]=85,"Sale New Customer",[callhist.resultcode]=982,"Automated Busy",[callhist.resultcode]=983,"Automated No Answer",[callhist.resultcode]=984,"Automated Telco",[callhist.resultcode]=988,"Automated Abandoned",[callhist.resultcode]=990,"Automated No Dial",[callhist.resultcode]=991,"Automated Fax",[callhist.resultcode]=993,"Automated Dropped Call",[callhist.resultcode]=994,"Automated Dial Failed") as resulttext, Count(CallHist.ResultCode) AS CountOfResultCode, CallHist.UserID, CallHist.QueueNo, Count(CallHist.QueueNo) AS CountOfQueueNo
FROM CallHist
WHERE (((CallHist.CallDT)>=[Enter Start date] And (CallHist.CallDT)<=[Enter End Date]))
GROUP BY CallHist.ResultCode,Switch([callhist.resultcode]=5,"Cancel After Card Declined",[callhist.resultcode]=6,"Card Declined Sent Admin",[callhist.resultcode]=7,"Spanish Speaker",[callhist.resultcode]=30,"Answering Machine",[callhist.resultcode]=31,"Abandoned by Agent",[callhist.resultcode]=45,"Not Now",[callhist.resultcode]=69,"Verified Number",[callhist.resultcode]=71,"No Contact",[callhist.resultcode]=72,"Wrong Number",[callhist.resultcode]=73,"Not Interested",[callhist.resultcode]=75,"Callback",[callhist.resultcode]=77,"Change Number",[callhist.resultcode]=80,"Sale",[callhist.resultcode]=85,"Sale New Customer",[callhist.resultcode]=982,"Automated Busy",[callhist.resultcode]=983,"Automated No Answer",[callhist.resultcode]=984,"Automated Telco",[callhist.resultcode]=988,"Automated Abandoned",[callhist.resultcode]=990,"Automated No Dial",[callhist.resultcode]=991,"Automated Fax",[callhist.resultcode]=993,"Automated Dropped Call",[callhist.resultcode]=994,"Automated Dial Failed"), CallHist.UserID, CallHist.QueueNo
ORDER BY CallHist.ResultCode;

I get a "Expression to complex in Query Expression"
Aug 10 '10 #7
dsatino
393 256MB
yes, this has to do with the number of things a Switch function can evaluate. You simply have more than it can take. If you're comfortable with VBA, you should definitely move this to a Select Case function which I believe can handle infinite choices.

If you're not, than you could UNION two SELECT queries in which one of them handles certain result codes and the other handles the remaining ones.
Aug 10 '10 #8
@dsatino

I am not sure with the VBA but I would like to learn :) how would I union if I got stuck.

Also, is the Union going to make things perform extremely slow? Would the VBA perform faster?
Aug 10 '10 #9
dsatino
393 256MB
A select case is easy in itself, but if you have no prior experience you're a long way away from returning results so lets stick with the SQL.

The UNION query does affect performance noticeably at high levels of detail, but when you UNION aggregate queries it's usually still very fast. Your UNION will look like this:

SELECT CallHist.ResultCode,Switch([callhist.resultcode]=5,"Cancel After Card Declined",[callhist.resultcode]=6,"Card Declined Sent Admin",[callhist.resultcode]=7,"Spanish Speaker",[callhist.resultcode]=30,"Answering Machine",[callhist.resultcode]=31,"Abandoned by Agent",[callhist.resultcode]=45,"Not Now",[callhist.resultcode]=69,"Verified Number") as resulttext, Count(CallHist.ResultCode) AS CountOfResultCode, CallHist.UserID, CallHist.QueueNo, Count(CallHist.QueueNo) AS CountOfQueueNo
FROM CallHist
WHERE CallHist.CallDT>=[Enter Start date] And CallHist.CallDT<=[Enter End Date] And CallHist.ResultCode<70
GROUP BY CallHist.ResultCodeSwitch([callhist.resultcode]=5,"Cancel After Card Declined",[callhist.resultcode]=6,"Card Declined Sent Admin",[callhist.resultcode]=7,"Spanish Speaker",[callhist.resultcode]=30,"Answering Machine",[callhist.resultcode]=31,"Abandoned by Agent",[callhist.resultcode]=45,"Not Now",[callhist.resultcode]=69,"Verified Number"),CallHist.UserID, CallHist.QueueNo
ORDER BY CallHist.ResultCode
UNION
SELECT CallHist.ResultCode,Switch([callhist.resultcode]=71,"No Contact",[callhist.resultcode]=72,"Wrong Number",[callhist.resultcode]=73,"Not Interested",[callhist.resultcode]=75,"Callback",[callhist.resultcode]=77,"Change Number",[callhist.resultcode]=80,"Sale",[callhist.resultcode]=85,"Sale New Customer",[callhist.resultcode]=982,"Automated Busy",[callhist.resultcode]=983,"Automated No Answer",[callhist.resultcode]=984,"Automated Telco",[callhist.resultcode]=988,"Automated Abandoned",[callhist.resultcode]=990,"Automated No Dial",[callhist.resultcode]=991,"Automated Fax",[callhist.resultcode]=993,"Automated Dropped Call",[callhist.resultcode]=994,"Automated Dial Failed") as resulttext, Count(CallHist.ResultCode) AS CountOfResultCode, CallHist.UserID, CallHist.QueueNo, Count(CallHist.QueueNo) AS CountOfQueueNo
FROM CallHist
WHERE CallHist.CallDT>=[Enter Start date] And CallHist.CallDT<=[Enter End Date] And CallHist.ResultCode>=70
GROUP BY CallHist.ResultCode,Switch([callhist.resultcode]=71,"No Contact",[callhist.resultcode]=72,"Wrong Number",[callhist.resultcode]=73,"Not Interested",[callhist.resultcode]=75,"Callback",[callhist.resultcode]=77,"Change Number",[callhist.resultcode]=80,"Sale",[callhist.resultcode]=85,"Sale New Customer",[callhist.resultcode]=982,"Automated Busy",[callhist.resultcode]=983,"Automated No Answer",[callhist.resultcode]=984,"Automated Telco",[callhist.resultcode]=988,"Automated Abandoned",[callhist.resultcode]=990,"Automated No Dial",[callhist.resultcode]=991,"Automated Fax",[callhist.resultcode]=993,"Automated Dropped Call",[callhist.resultcode]=994,"Automated Dial Failed"),CallHist.UserID, CallHist.QueueNo
ORDER BY CallHist.ResultCode;
Aug 10 '10 #10
@dsatino

I want to just say thank you very much for all your help on this. I have really one more question in regards to grouping all of this together in a sort of summary.

Should I do this sum? in a query or on the report in access?

Basically what I am trying to accomplish is this.

I want to see the following columns in an Access Report

UserID Queue5 Queue0 Queue1 AnsweringMachine Busy

I want the report to show UserID 2005 and then do a count of all the calls made in queue5 under that column and a count of all the calls in queue0 and so on. Currently it shows

UserID ResultCode QueueNo
2005 80 5
2005 80 0
2005 45 1
Aug 11 '10 #11
dsatino
393 256MB
I'm not sure this layout is what you're looking for. From the looks of it, a call can't be in multiple queues and can't have multiple results so your report will have 'staggered' (for lack of a better term) and duplicate results. They will probably look something like this:

UserID Q5 Q0 Q1 AnsM Busy
2005 1 1
2005 2 2
2005 3 3

In this example, the 1 under Q5 is the same as the 1 under Busy because you don't have counts for Q5 or counts for Busy, rather the counts are representative of a grouping of UserId, result, and queue combined.

Long story short, what you want to do is create a Crosstab query from the UNION query. Set UserID as row heading, resulttext as a row heading, queueno as a column heading, and your count as the value. Then build your report from this crosstab query and group the report by userid with the header and footer sections turned on. The report will look like this.

2005 Q1 Q2 Q3 etc.

Busy 4 2 1
AnsMac 2 0 1
etc.


The Q headers in this example are in the UserID header, but you can put them in the page header as well. You can also sum the columns in the footer, I was just too lazy to type that out. But you shoud get the gist of it
Aug 11 '10 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: ABC | last post by:
Which statement on the C# has live-as VB's "With" Statement?
4
by: doodle | last post by:
access 97 can someone tell me the syntax for a with stement for multiple controls? pseudo (doesn't work) With cmbBox1,cmbBox2,cmbBox3 .Visible = False End With
3
by: Ashok Guduru | last post by:
Hi, I'm new to C#. In VB.NET we have With...End With Statement. Often, I need to perform several different actions on the same object. For example, I may need to set several properties or...
1
by: Gunawan | last post by:
Hi All, When using vb I could use with statement to make access to property/method shorter Dim cmd AS new SqlCommand with cmd.parameters .AddWithValue() .... end with
33
by: =?Utf-8?B?RE9UTkVUR1VZ?= | last post by:
Hello, In vb.net there is a with statement, Is there are similar constructor in c#?
11
by: Nhan | last post by:
Hi, is there equivalent statement in C# as WITH ... END in VB? instead of: frm.dataGridView1.AutoGenerateColumns = true; frm.dataGridView1.DataSource = l_oDataset;...
2
by: Dmitry Teslenko | last post by:
Hello! I've made some class that can be used with "with statement". It looks this way: class chdir_to_file( object ): .... def __enter__(self): .... def __exit__(self, type, val, tb): ....
2
by: mk | last post by:
Hello, I'm trying to learn how with statement can be used to avoid writing: prepare() try: something_that_can_raise_SomeException() except SomeException, err: deal_with_SomeException...
4
by: braver | last post by:
Can open two files in a with statement: with open(src) as readin, open(dst,"w") as writin: # WRONG: comma doesn't work ... -- so that you have transactional safety for two file descriptors?...
5
by: peppergrower | last post by:
I've been experimenting with the 'with' statement (in __future__), and so far I like it. However, I can't get it to work with a cStringIO object. Here's a minimum working example: ### from...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.