access iif query do nothing when false - ms-access

My situation/problem:
TableA
id, postalcode, region
Criteria for the field i want to add value in (postalcode):
=IIf([tableA.Region]="Chicago","60064",[postalcode])
What i need to accomplish is an iif-query where:
In the field postalcode I check in the criteria if the field region equals Chicago. If so fill up the field with postalcode 60064 if not DO NOTHING
For the do nothing part I'm using the fields name, this is wrong?
am i using the criteria in the right field (the field i want to add?)
I'm using a selection query?
As you can see i'm a noob in access queries...
Can somebody give me the right iff statement?
Thx in advance,
D

I'll suggest you bracket table.Region differently, or eliminate the brackets there entirely.
=IIf([tableA].[Region]="Chicago","60064",[postalcode])
=IIf(tableA.Region="Chicago","60064",[postalcode])
If that doesn't fix the problem you're trying to solve, tell us more about the problem. If you're getting an error message, tell us what it says.
Taking a wild guess, that code as a field expression in a query will not give you an editable column in the query result set. If you want to pre-load a column value based on your criteria, but then allow the user to change the value, use a form. In the form's On Current event, load the value as you wish.

This is a dead old post but I think this was what you wanted:
=Like IIf([tableA.Region]="Chicago","60064",'*')

As far as I can understand,
if not DO NOTHING
You need to return nothing if the condition is false.
What you need is the WHERE clause instead of IIF

If I'm understanding your question correctly, you want a NULL value in Postal Code if it's not Chicago?
=IIf([tableA].[Region]="Chicago","60064","")

Please add another IIF query as OR
IIf([Forms]![Run_Macro
Form]![ReturnType_DrpDwn]="Monthly",[Forms]![Run_Macro
Form]![Cmb_Per_Ending],#1/1/2010#)
IIf([Forms]![Run_Macro Form]![ReturnType_DrpDwn]="Quarterly",#1/1/2010#,#1/1/2025#)

Related

How do I get an expression in SSRS report to change with a department parameter?

Here is the code for the expression. I want it to change with the chosen parameter, which are different departments for a company. Right now it is just set to show the "First", but I don't know what other syntax to use.
=First(Fields!Description.Value, "Departments")
So going back to my original solution, I think it will work for your needs. It appears you have a single-select parameter.
You would just need to enter =Parameters!Department.Label into your expression for that field and I think that would take care of the problem.

Dlookup on textbox is not working

I have been researching on MS-Access topics around DLookup, but not being lucky on the resolution of my problem.
I have a query that solely returns one value, which is a lumpsum of credits. So I used the clause "AS TOT_CREDIT" on the query to give the unique column a name.
On access report, I learned that you can't directly set the value of a textbox from a query, but also learned the magic is to set the textbox controlsource property to dlookup, like this: dlookup([TOT_CREDIT]; [QUERY THAT CONTAINS TOT_CREDIT]). When I pull the report from access, the textbox still displays the infamous "#Name?", instead of the query value.
Is anything missing here? What else can I do in order to have the textbox display the query result?
Must use quotation marks:
DLookup("[TOT_CREDIT]"; "[QUERY THAT CONTAINS TOT_CREDIT]").

In Access VBA expression builder, how do I sum a column conditionally?

Let's say I have two fields A and B and one textbox B_input. I would like to set up a query so it sums all entries of column A where B = B_input
Currently I have:
==Sum(IIf([B_input]<>"All",[A],IIf([B_input]<>[B],0,[A])))
I did more testing, it seem the problem is that under Sum(IIF([B_input])), it's not recognizing the value of [B_input], but if I just have IIF([B_input]), it recognize the value just fine, any ideas?
iif([B_input]=="xyz",Sum[A],False)
Might be what you're after but I'm not sure i understood your question properly.
Alternatively, just edit the sql to something like
SELECT(SUM[A]) AS SumOfA FROM [MyTable] HAVING ("B"="xyz");
How about:
=Sum(IIf([B_input]<>"All",[A],0))
Gave up, went with form filtering instead.

Adding optional filter in SSRS 2008

I am trying to add an optional filter on a text field in a report. I have tried setting it up in the dataset but it treats it as a required filter so if it is not populated, no results are returned. It needs to use the Like operator. Any advice?
As I was typing out a work-around to this problem, I realized an incredibly easy solution (now that I understand better how it works).
Here's what I did:
Since Hong pointed out that all filter conditions must be met, I reversed my thinking. I moved my existing "IN" filters to the query and fed the parameter directly to the query. Then I created by "LIKE" text filter on the report which a default value of "*" so it would immediately return everything.
Here's what I could've done:
Just the last part. Added the "LIKE" filter with a default value of "*" so it immediately returned everything.
I also agree that most of the time it's best to send the params back to SQL. Since that's not what the OP is asking, here is the best option I have found for doing this. And it is actually quite simple.
Add your parameter with the appropriate data type. Let's use the
example of a "City" in this case (a text/string field).
Check "Allow Nulls" on the parameter.
Add a filter to either a tablix, table or dataset.
In the expression, select the field you want to filter on. Select the appropriate operator, in my example of a data set with Cities, in the Value put in this:
=IIF((Parameters!City.Value Is Nothing), Fields!City.Value, Parameters!City.Value)
I don't think you can make an optional filter in DataSet Properties/Filters, adding filters there means returning results that match ALL filter contiditions, so it is "AND" logical relation among all filters, not "OR".
My sugguestion is to use filter in query designer of the dataset, where you can define "OR" relations to filter out data. For instance: Your_Text_Field="SomeValue" OR Your_Text_Field is Empty.
Although I agree that most of the time it is best to send the parameters back to the stored procedure or data layer to reduce the amount of data returned, I have a case where it is just as easy to do the parameter handling in the RDL file via a filter. Due to this unique situation I found this solution which gives you a way to create an Optional filter in the RDL file.
http://www.andrewshough.com/development/sqlserver/ssrs/optional-filter-in-ssrs/
It is a great blog post with easy step by step instructions on how to create an optional filter.
Please Note: This is NOT my blog but I though this solution was great for what I needed and I hope it helps someone else when they google for "optional filter in SSRS" like I did.
I found a post which solved my problem setting the filter for a report-consumer to a) all multivalue fields being selected so the user b) could specify his/her selection if necessary.
Kasim 8 Dec 2010 8:55 AM #
In reports when we want to default the multivalue parameter to 'Select All' following are the steps.
Open the Report parameter window from the Report menu.
Select the Report parameter from the left handside of the window.
Select 'Multi-value' checkbox and appropriate 'Available values'.
Under default values select 'From Query' radio button'.
Select the appropriate 'Dataset'.
Select appropriate 'Value Field'.
Save the Report and select Preview Tab. You will find all the items selected in the multivalue >parameter list and the result displayed for all the selected items.
found on: http://blogs.msdn.com/b/bimusings/archive/2007/05/07/how-do-you-set-select-all-as-the-default-for-multi-value-parameters-in-reporting-services.aspx
(The Post came up in the comments quite in the middle.)
You can accomplish this by using an expression on the dataset filter.
Check this

SQL to populate a hyperlink column in MS Access

I imagine the SQL must pass 2 values, the value shown in the table and the link to which that value navigates.
I'd appreciate a pointer to the SQL Script for achieving this. Thanks.
The format for a hyperlink column (field) is:
Description#Address#
For example:
This is StackOverflow#http://stackoverflow.com#
Mr E Xample#mailto:example#example.com#
For the most part, I prefer to avoid hyperlink fields (columns) as editing them is a real problem. A text or memo field with a little code is much simpler, though you will need a form.
If you're looking for a query to extract the Description and Address from a hyperlink field, try this:
SELECT
hlink,
Left(hlink,InStr(1,hlink,"#")-1) AS link_description,
Mid(hlink,InStr(1,hlink,"#")+1,InStr(InStr(1,hlink,"#")+1,hlink,"#")-InStr(1,hlink,"#")-1) AS link_address
FROM tblHyperlink;
It's sure not pretty. And it will return #Error for hyperlink fields which are Null or contain less than two # characters.