concatenate using Allen Browne's example - ms-access

I am using the 'concatenate related' module created by Allen Browne to concatenate rows into a single field. At first I had a lookup field at the table level and later realized this is not a good approach. So I deleted the lookup column and instead made a query for selecting values from the lookup table on my form and then store that value as a number in the table.
The module works when I concatenate the values but it is listing the number (id) whereas I would like the actual description (i.e. 1 = Red, 2 = Blue, etc.)
My SQL query code is as follows:
SELECT DISTINCT
tblCompany.JobID,
concatrelated("type","tblMonitor","JobID = " & [jobID]) AS Expr1
FROM tblCompany;
I would like "type" to display the description instead of the number. I know if I store my lookup value as text instead of number it will work. But for efficiency it seems the number should be stored in the table and then query for the description when you need it....or maybe text is fine??? I'm guessing I would need to add the lookup table to this query. I have tried but with no luck so far.

Create a query which joins tblMonitor with the table which holds the type description field. Then use that query with ConcatRelated.
ConcatRelated("type_descriptn","YourQuery","JobID = " & [jobID])

Related

Comparing multiple fields in two datasets to return a 3rd value

I am in report builder and I have my primary dataset that is from a SQL database, I also then created a second dataset (enter data). I need to compare 2 fields from each dataset to retrieve the correct value from the 2nd dataset and populate a column on my report. I have tried the IIF statements and Lookup statements but I keep getting the error "report item expressions can only refer to fields within the current dataset".
I have a attached a screenshot of what I am trying to do....
The IIF statement I tried to use.. If Acctnum and prodid = each other return IncodeNumber
=IIF((Fields!AcctNum.Value=Fields!AcctNum.Value, "IncodeAccount") AND
(Fields!ProdId.Value =Fields!ProdId.Value, "IncodeAccount")),(Fields!IncodeNumber.Value, "IncodeAccount"),"True")
See code in my problem.
You need to use LOOKUP(). The problem with LOOKUP() is that is can only compare a single value from each dataset. However, we can easily get around this issue by concatenating the two values you need to compare.
Note: This assumes the expression will be in a tablix that is bound to your first dataset and that IncodeAccount is your second dataset - the values you want to lookup. If this is not the case just adjust the expression accordingly
So for you, you probably need to do something like this..
=LOOKUP(
Fields!AcctNum.Value & "||" & Fields!ProdId.Value,
Fields!AcctNum.Value & "||" & Fields!ProdId.Value,
Fields!IncodeNumber.Value,
"IncodeAccount"
)
I've used two pipe symbols to join the values to avoid incorrect matches being found. e.g. Account 123 and product ID 4567 would incorrectly match to Account 1234 and product ID 567 as they would both be 1234567 when joined. By using the || the match would be 123||4567 and 1234||567 respectively.
You may need to convert the values to string using CStr()
Alternative approach
If you are going to do this 'join' multiple times in the same dataset then you could add a calculated column to the dataset that concatenates the two columns. Then you can use this single field in the lookup which will make things a little simpler.
Or, you could do this concatenation in a database view which would make things even easier.

Use IIF and LIKE statement in critera column in queries, MS Access

I have homework from Microsoft Access for school and one of the tasks was to make a search form in query, where you type for example 1. grade, 2. grade or 1st year, etc... But the field contains the name of the classes such as IT1, IT2, E1A, E3C, etc... So I could not just make a search form with [Enter Class:] or Like [Enter Class:]&"*" in the criteria column. So I was thinking, that I can use the IIF statement but it doesn't work how I imagined. I think there is a problem with the LIKE statement. I read on forums, that the IIF statement should be used in the field column but I tried the simple examples in the criteria and it worked just fine. So my question is, how I can make a search form, where I type numerous letters with one certain number in it BUT only the number will be read and returned with the same number in classes. Example: I type to search 1. grade and the value will return classes IT1, E1A, E1B, E1C, E1D. This is the line I used in the criteria column:
Like IIf([Enter the grade:]="*1*";"*1*";IIf("*2*";"*2*";IIf("*3*";"*3*";IIf("*4*";"*4*"))))
Just to qualify, I'm beginner in access and databases overall, so there is big possibility, that I'm missing something.
Thank you for help! Cheers!
Assuming input will always start with a number and you want all values containing that number, consider:
WHERE fieldname LIKE "*" & Val([Enter grade]) & "*"
Also assumes values contain only single digit.

How to roll up a column with a query

i have an acess "query" that consist of Drawing-title and Multiple data per ID. And i would like to roll up this data into separate columns. Thanks in advance.
My query looks like this
And would like to change to this
A CROSSTAB requires 3 fields. You need to calculate a third field as a sequence number for each group that will become RowHeader. This will require a unique identifier field in table - autonumber should serve.
TRANSFORM First(Data) AS FirstData
SELECT DWG
FROM tableORquery
GROUP BY DWG
PIVOT DCount("*","tableORquery","DWG='" & [DWG] & "' And ID<" & [ID])+1;

SSRS Data from one dataset not in another

I've been searching for a possible answer to my problem but was unable to find one. Lets assume that I have 2 datasets. dsMediaServerData has two columns: id and channel. I have other dataset (dsCatalogData) with a lot of columns including id and channel. I want to filter dsCatalogData to show only those records that are not in dsMediaServerData.
My recommendation would be to update the SQL queries used to populate the datasets so that duplicate id/channels are excluded.
If you can't do this directly through SQL because the data sets are coming from different DB's, you can accomplish this with the use of a parameter.
1) Let's start with the first dataset (dsMediaServerData in your example). Since your example shows filtering by 2 columns, but the data will be travelling through a single parameter, you will need to create a new column that combines both pieces of data.
SELECT Convert(VARCHAR(255), id) + '_' + Convert(VARCHAR(255), channel) as 'combined_columns_to_filter'
2) Now create a new parameter (let's call it #filter).
Set the data type to text
Check "Allow multiple values".
Open up "Default Values" and choose "Get values from query". Choose the dsMediaServerData data set and select the new column 'combined_columns_to_filter' as the value field.
Set the visibility to "Hidden" so that users don't try to interact with this parameter.
3) Now update the second dataset. Add the #filter parameter to the WHERE clause.
WHERE Convert(VARCHAR(255), id) + '_' + Convert(VARCHAR(255), channel) NOT IN (#filter)
This should effectively filter the second dataset by removing all records found in the first data set even though the data sets are in separate databases.

MS Access Query using IFF to compare values

I am trying to build a query which will look at the data in two fields in two different tables and check to see if the data is the same, if it is I want it to return the number of times it is matched, if it isn't I simply want it to return the text saying "No viewings".
I have constructed this query in my access database which has the field from the first table "Property" and the second field I want it to compare the data with, "Viewings". I have build the following expression using the build tool, however I am stuck to make it work since every time I get this error message when trying to run the query: "Your query does not include the specified expression 'Property Viewed' as part of an aggregate function."
totalViewings: IIf([Viewings]![Property Viewed]=[Property]![ID],Count([Viewings]![Property Viewed]=[Property]![ID]),"No Viewings")
Any help how to overcome this error would be very appreciated.
Thanks
I would suggest doing something like this:
1) Assuming this is something you are developing yourself, make sure your data structure is all in order first. Since I dislike relatively code-hostile identifiers, I'd have the tables as so -
Properties - PropertyID (AutoNumber, primary key), HouseNumberOrName, Street, etc.
Viewings - ViewingID (AutoNumber, primary key), PropertyID (Number/Long Integer), ViewingDate, etc.
In the Relationships view, Properties.PropertyID would then be set up to point to Viewings.PropertyID in a one-to-many relation.
2) Your actual query I would then break into two, the first to compile the data and the second to format it for display. The first would go like this, saved as ViewingCounts...
SELECT Properties.PropertyID, Count(Viewings.PropertyID) As ViewingCount
FROM Properties LEFT JOIN Viewings ON Properties.PropertyID = Viewings.PropertyID
GROUP BY Properties.PropertyID;
... and the second like this, saved as ViewingCountsForDisplay:
SELECT Properties.*, IIf(ViewingCount = 0, 'No viewings', ViewingCount) AS Viewings
FROM Properties INNER JOIN ViewingCounts ON Properties.PropertyID = ViewingCounts.PropertyID
ORDER BY Properties.PropertyID;