I need to generate two letters to a person (one for each address). How can I accomplish this? - sql

I would like to create two letters for a single person. One letter will be sent to a person's old address and another will be sent to a person's new address. Would this be two different reports with a slight variation in the SQL or is there a way to simply create both letters with a single report?

In a normallized database, you would show the old address and new address in two separate records, perhaps in a related table linked by person ID or something similar. You should look up and read about normalization. Certainly you should aim for at least 3rd normal form.
For your current problem, you could create a unionized view
select NewAddress As Address from TableName
union
select OldAddress as Address from TableName
Then report on the values in the view.
You might want to have some more fields as well, such as the person's name.
The fields you select in the first select statement must be the same number and type as those in the second select statement.
Also you can still add a where clause and an order by clause.
Check on the union operator online.
Hope this helps
Harv

There are a couple of approaches you could use:
union the old and new addresses in the query, then report on the query with a single detail section for each dataset row.
alternatively, report off the Table and include two detail rows, one each for the old and new address, and conditionally suppress each section depending on whether the relevant address is NULL.

Related

view unique values in Combobox using VBA in MS Access

please read my question to end because I test all previous solutions in Stackoverflow and have no answer.
I am trying to display Combobox in the form of an MS Access database using VBA, this Combobox takes its values from one table the problem that I can't display just unique values, Combobox views all values even when I use DISTINCT still view all.
also, I am trying to use GROUP BY but not work.
I know it is a simple problem but how can I solve it?
SELECT DISTINCT Exports_imports_Table.ID, Exports_imports_Table.content FROM Exports_imports_Table;
Assuming the ID field is a unique value (and the content field may have duplicates) you cannot include it in a DISTINCT. Try it like this
SELECT DISTINCT Exports_imports_Table.content FROM Exports_imports_Table;
Does that give you what you expect?
Don't take the ID field in your query builder. Instead of that, select the same field twice, leaving one of them as is, and in another you can give your conditions or formats (if any).
Make sure to change unique values in general properties to "yes".
Save it, and there you are.

What's the fastest way to concatenate items from several lines into one field?

In ABAP, what would be the fastest way to concatenate items of the same field from multiple lines into a field of one line?
My program is supposed to report a list of payments, the vendor's ID, and the vendor's email addresses.
Email addresses are stored in table ADR6, one line per address, along with the vendor's ID they belong to.
For the report I would need an internal table populated with vendor IDs (unique key) and concatenated email_addresses, separated by semicolons.
How to populate this internal table?
There is no real magic way to concatenate some fields from a table. Just use something like:
data: email_addresses type string.
loop at [table with addresses] assigning field symbol(<address>).
at first.
email_addresses = <address>-[email field].
continue.
endat.
concatenate email_addresses ';' <address>-[email field] into email_addresses.
endloop.
Only faster method I can think of would involve native SQL.
HANA Solution
Use string_aggr:
SELECT vendor, STRING_AGG(email_address,';')
FROM ADR6
GROUP BY vendor;
HANA Academy has a video demonstrating the use, along with sample code. Note that this solution requires HANA SPS09.

Database Search that Compares Results for Mutiple Seach Keywords

Fist, let me say I know very little about SQL language and am trying to learn (albeit very slowly). I have created a database table with columns for
ECOREGION_ID
ECOREGION_NAME
SPECIES_NAME
CLASS
so that there is one row for each species name in each ecoregion. My end goal is to create a form in which I can enter in multiple species names and search for the ecoregions they share. For example, if I enter into the 4 different search boxes "Tiger", "Red Panda", "Sloth Bear", and "Rhino" it would bring up a list of all the Ecoregions in which these four species share. I am wondering a few things:
Is my data set up in the correct way in order to do this or is there a more efficient way to set i t up?
What statement should I use to create an sql statement to perform the search I want?
What is the technical term for what I am wanting to do? I have tried many different searches on different forums and can't seem to find what I am looking for, mostly because I probably don't know what to search, lol.
Thanks,
-Drew
You have ECORegion_ID and ECORegion_Name in the same table. I would suggest create a separate table to hold ECORegions. This table would have both an ID and Name. The search table would then only have the ECORegion_ID. This process is called normalization. It basically reduces redundant data in your database.
You are looking for a SELECT statement, which is used to pull data out of one or more tables. The statement has a WHERE option to restrict which rows you bring back and an IN expression as part of the WHERE to allow you to look for multiple keywords.
Search for Normalization to see why to put region name in a separate table. Look up SQL Select to get syntax for the select statement you should get off to a good start

Searching Sqlite

I was wondering if there was a way to search an entire SQLite database for one specific word. I do not know the column that it is in or even the table that it is in.
The table and row/column that contains this specific word also contains the other entries that i need to edit.
In-short:
Need to find a specific word
Can't query (i don't think i can atleast) since i don't know the table or column name that its located in.
I need to know where this specific word is referenced. In what table and row so I can access the others that are along side it.
Basically, is there a CTRL+F functionality of SQlite that searches the entirety of the SQLite file?
I have mac/windows/linux machines. I am not limited by software if that is a solution.
Any such functionality would essentially be running queries that check every column of every table. You can do that via a script that runs the following SQL:
1) Get a list of all the tables:
select name from sqlite_master where type = 'table'
2) For each table, get all of its columns (column name is available in the name field)
pragma table_info(cows)
3) Then for each table, generate a query that checks every field and run it:
select
*
from cows
where name like '%Daisy%'
or owner like '%Daisy%'
or farm like '%Daisy%'

Dynamic query creation

I have a scenario wherein with the following details:
I have a form that contains fields like firstname,middle name,lastname,dob,pin,address for Client 1.
Now this form has to cater more than one client . The problem statement is - different clients may require different number of fields to be displayed on front end. For eg: a 2nd client would want - Country field instead of pin, would not require address on the form.
Now when i submit the form , currently i have a constant query which takes values of - firstname,middle name,lastname,dob,pin,address and inserts it into database for Client 1. I want to develop a query in a way that it is created at runtime and inserts only the values that come from the form into the database..
I hope my problem is clear. Can anyone help?????????????
You need to think about why you are doing this.
It will get hideously complex with just person form, add in more and it will balloon big style.
Dynamically building queries isn't particularly complicated, but it's a lot of code to do it.
Just think about each field you want to add to the query and it's type. What if a property on your person record was an image of them.
Do you have a configuration of the form, is the promary key on the record an auto inc, is it a compound key, do you use defaults, are some fields not null. How are you going to bubble back referential integrity exceptions...
Do the all singing all dancing version and basically you reinvent something like the Access IDE....
Personally I'd have a Person object with a set of Person Properties, they would have name, a value and a boolean to say whether they'd been changed.
Once you have teh list of chnaged properties and beacseu you are in the Person object you know the table is persons, it's keyed by an autoinc bigint, gender is mandatory and defaults to Male...
You have a fighting chance.
Your query should use parameters
So it would be say Insert Persons(FirstName, LastName, PIN) Values(#FirstName,#LastName,#PIN)
Then you'd nip through your changed fields and add parameters with same name, type and value.
As I said you can really go to town with this one, may be it's time for a night in though.
This should mean that some fields in your table like address and pin can be empty, in that case you can do without a dynamic query. Just collect all the inputs from your form and insert them into your table. Those form fields that were left empty due to different user needs will consequently have their corresponding field in your table empty. So just list all the needed fields in your table and all the possible input from your form in your insertion query.