RDLC: How to write the correct logical statement to display different address lines? - rdlc

I need to change the logic in rdlc statement to display 2 address lines in address section.
The address section can be generated as one of the following:
Company Name
John Smith
Address 1
Address 2
City, State, Zip
Company Name
John Smith
Address 2
City, State, Zip
Company Name
John Smith
Address 1
City, State, Zip
I have a logic that displays empty line if Address 2 is empty or does not exists:
Company Name
John Smith
Address 1
City, State, Zip
This is my statement:
=First(Fields!Address.Value, "Dataset") & VbCrLf &
IIF(IsNothing(First(Fields!Address2.Value, "Dataset")) or First(Fields!Address2.Value, "Dataset") = "","",
First(Fields!Addess2.Value, "Dataset")) & VbCrLf &
IIF(IsNothing(First(Fields!Address3.Value, "Dataset")) or First(Fields!Address3.Value, "Dataset") = "","",
First(Fields!Address3.Value, "Dataset"))
What am I doing wrong and what is the right way to do it?

Related

Combining various rows in a table based on a condition

need some help to construct a PostgreSQL query. I am trying to combine various rows in a Postgres table based on a certain condition.
Here's what the table looks like
Roll_No
Role
Address Type
Address Value
0538
Home
Address Line 1
123 Main Street
0538
Home
Address Line 2
London
0538
Home
Address Line 3
Rogers Street
0538
Home
Address Line 4
United Kingdom
0538
Office
Address Line 1
Adam Land
0538
Office
Address Line 2
Valley Forge PA 19482
0538
Office
Address Line 3
U.S.A
0738
School
Address Line 1
Rogers Street
0738
School
Address Line 2
London
0738
School
Address Line 3
Holland Lane
0738
School
Address Line 4
United Kingdom
I want to concatenate all address values of a specific role (eg. home, school, office) into one column. Address type can contain values like Address Line 1 to 8. Here, Home has Address Line 1 to 4 whereas office has Address Line 1 to 3.
Roll_No
Role
Address Type
Address Value
0538
Home
Home Address
123 Main Street, London, Rogers Street, United Kingdom
0538
Office
Office Address
Adam Land, Valley Forge PA 19482, U.S.A
0738
School
School Address
Rogers Street, London, Holland Lane, United Kingdom
Use array_agg() function for combining column value with comma. Here ORDER BY clause isn't used because address line 4 wouldn't come before address line 1. Extra ORDER BY clause can degrade query performance for a large data sets
-- PostgreSQL
SELECT roll_no, role
, role || ' Address' address_type
, array_to_string(array_agg(address_value), ', ') address_value
FROM test
GROUP BY roll_no, role
ORDER BY roll_no, role;
Please check this url https://dbfiddle.uk/?rdbms=postgres_11&fiddle=e46cf351452a2715258b69afeea5c742
If ORDER BY must needed inside array_agg() function then use the below query
-- after applying order by inside array_agg()
SELECT roll_no, role
, role || ' Address' address_type
, array_to_string(array_agg(address_value order by address_type), ', ') address_value
FROM test
GROUP BY roll_no, role
ORDER BY roll_no, role;
Please check the url https://dbfiddle.uk/?rdbms=postgres_11&fiddle=c196a9a2ca71bd886e4750b935d23040
If same address stored for multiple address line of a particular role for specific roll_no then DISTINCT keyword will use inside array_agg().
-- after applying distinct inside array_agg()
SELECT roll_no, role
, role || ' Address' address_type
, array_to_string(array_agg(DISTINCT address_value), ', ') address_value
FROM test
GROUP BY roll_no, role
ORDER BY roll_no, role;
Please check this url https://dbfiddle.uk/?rdbms=postgres_11&fiddle=e4f0de7c37e003133e2539149db245f8
You may use ARRAY_AGG() inside ARRAY_TO_STRING() but with caution. Because generally, SQL tables are unordered sets. Hence explicitly mentioning ORDER BY inside array_agg() is very very important.
Code:
SELECT
Roll_No,
role,
role || ' address' AS address_type,
array_to_string(array_agg(addressvalue ORDER BY roll_no, role, addresstype), ', ') as address_value
FROM t
GROUP BY Roll_No, role
ORDER BY roll_no, role, address_value
Look at the db<>fiddle. Take a look how results vary with and without ORDER BY inside array_agg().

Separate multiple selected address from GetAddress Method

This is a simple question really.
But I'm having a hard time to solve it.
Background:
I'm trying to get email address using .GetAddress Method of Word.Application Object.
Now, I don't have problem if the user selects single To and CC recipients.
Problem occurs when multiple emails get selected by the user.
For example, the user selects two email address and one group list.
rawRecip = Application.GetAddress(, "<PR_DISPLAY_NAME>", , 1, 2, True)
Debug.Print rawRecip
Using above code produces:
Smith, John, Joe, Jane, All-HQ Group
Each address selected is separated by a <comma><space>.
The problem is SurName and GivenName are also separated by the same.
Now I need to successfully get the display name of the 3 address selected by the user.
Split function doesn't get me anywhere since I cannot find or generate a unique delimiter that would separate the 3 display name.
Is there a clean way to get what I want?
Smith, John
Joe, Jane
All-HQ Group
Unbelievable. The answer is already in front of me.
Posting this as answer just in case someone needs it.
You just need to add another character in the GetAddress Method.
Edit:Using another space character gives the best result
rawRecip = Application.GetAddress(, "<PR_DISPLAY_NAME>" & " ", , 1, 2, True)
It will produce:
Smith, John , Joe, Jane , All-HQ Group
Then you can use Split function and some text manipulation to get the desired result.
Dim i As Integer, dName
dName = Split(rawRecip, " , ")
For i = LBound(dName) To UBound(dName)
Debug.Print dName(i)
Next
And the result:
Smith, John
Joe, Jane
All-HQ Group
Note:with extra space on the last entry

SQL Match City Name Inside Full Address?

How would you list the people from a database that are not from 'London'?
Say the database is:
Cust_id address
1 33 avenue, Liverpool
2 21 street 12345, London
3 469 connection ave, Manchester
I'd like to list the customers that are NOT from London. Here's what I've tried:
select Cust_id from customers where address <> 'London';
Now when I do that, it lists all the customers, regardless of location.
Help would be greatly appericated.
Not ideal but might satisfy your requirements:
select Cust_id from customers
where address NOT LIKE '% London%';
[Note the added space: it assumes you will always precede the city name with a space. '%London%' would match words containing London]
(It might be better if you had a normalised address, i.e. broken into street address, town, city, etc.))
Try this:
select Cust_id from customers where address not like '%London%';
or this:
select Cust_id from customers where not address like '%London%';
Both of these are OK.
For more details on LIKE see e.g. here: SQL LIKE

sql create a field from a field

I need to run a query that would pull information from a field that has 2 types of data .
Field is address and has 123 avenue as data and bb#yahoo.com.
I need to make 2 fields one for email and one STaddress from table customer and field address?
anyone can i assis..
its access and vb query
I thought of this
Select customer.address from customer where address like "#"
but still i need to display the the data of address field to 2 different fields...
Here is the query that fetches the two different fields:
select iif(field like '*#*', field, NULL) as email,
iif(field like '*#*, NULL, field) as address
from t
The usage of like in Access is a bit different from other databases.
I would suggest that you create a view with this logic. If you actually want to modify the table, you will have to add columns and populate them with logic like the above.
Based on this question and your duplicate question, I understand your table has a field which includes both the street address and email address and you want to split those into separate fields.
So your table includes this ...
YourField
------------------------------
1234 ave willie haha#yahoo.com
123 avenue bb#yahoo.com
And you want this ...
YourField street_address email_address
------------------------------ --------------- --------------
1234 ave willie haha#yahoo.com 1234 ave willie haha#yahoo.com
123 avenue bb#yahoo.com 123 avenue bb#yahoo.com
If that is correct, you can use the InstrRev() function to determine the position of the last space in YourField. Everything before the last space is the street address; everything after is the email address.
SELECT
y.YourField,
Left(y.YourField, InstrRev(y.YourField, ' ') -1) AS street_address,
Mid(y.YourField, InstrRev(y.YourField, ' ') +1) AS email_address
FROM YourTable AS y;
You may need to add a WHERE clause to ensure the query only tries to evaluate rows which include your expected YourField value patterns.
Try something like this:
select *,
(case locate('#', address) when 0 then null else address) as email,
(case locate('#', address) when 0 then address else null) as street
from table;
You'd probably need to adjust the name of "locate" function - I'm not sure if it is the same in access database.
If you have a street address and then an email address in the same field, and want to split them, then use this.
We'll call your original field Addy, and the new fields Street & Email.
SELECT Left(Addy, InStrRev(Addy, " ", InStr(Addy, "#")) - 1) AS Street, mid(Addy, InStrRev(Addy, " ", InStr(Addy, "#")) + 1) AS Email.
What this does is look for the #, then go backwards and look for the first space. The first function takes every left of that space and calls it Street, while the second function takes everything to the right.
The function is really 3 functions nested together. To really understand what it's doing, I'll dissect it.
I = InStr(Addy, "#")
J = InStrRev(Addy, " ", I)
Street = Left(Addy,J-1)

SQL Syntax in MS Access Form

I have a problem of SQL syntax which I have been struggling for days.
I have created an MS Access 2010 Form called IP Country Form into which I want to insert into a TextBox called Country the Country obtained from the following query which queries a table called IPLocation which contains the Countries according to IP Numbers with the fields:
IPNS IPNE CY2(2 letter Country Code) CY3(3 Letter country Code) Country (full Country Name)
The table rows looks like this:
IPNS | IPNE | CY2 | CY3 | COUNTRY
19791872 | 19922943 | TH | THA | THAILAND
The form calculates the IP Number from the IP address and places it in a TextBox called IPNumber, which I then use in an SQL Query to obtained the Country which corresponds to it.
My current query is:
SELECT IPLocation.IPNS, IPLocation.IPNE, IPLocation.CY2, IPLocationCY3, IP.Location.Country
FROM IPLocation
WHERE (((IPLocation.IPNS)<" & [Forms]![IP Country Form]![IPNumber])
And ((IPLocation.IPNE) > " & [Forms]![IP Country Form]![IPNumber]))
IPNS, IPNE are Numbers as is IPNumber
Essentially the query is designed to find the Country where the IPNumber lies between IPNS and IPNE.
Any help would be much appreciated.
A test query I use:
Set rst = dbs.OpenRecordset("
SELECT IPLocation.IPNS, IPLocation.IPNE, IPLocation.CY2, IPLocation.CY3,
IPLocation.Country
FROM IPLocation
WHERE (((IPLocation.IPNS)>19791871)
AND ((IPLocation.IPNE)<19922944))
")
Works fine and returns the correct country
On the query you use on your code you have the comparison operators reversed on the AND clause.
IPLocation.IPNS) > " & [Forms]![IP Country Form]![IPNumber]
IPLocation.IPNE) < " & [Forms]![IP Country Form]![IPNumber]
Should be:
SELECT IPLocation.IPNS, IPLocation.IPNE, IPLocation.CY2, IPLocationCY3,
IP.Location.Country
FROM IPLocation
WHERE (((IPLocation.IPNS) > " & [Forms]![IP Country Form]![IPNumber])
And ((IPLocation.IPNE) < " & [Forms]![IP Country Form]![IPNumber]))