Removing Partially Matched Duplicates from a List - duplicates

I have a list of many email addresses. Formatted similarly as follows:
Business Name 01 email#business01.com; other#business01.com; info#business01.com; email#business01.com; other#business01.com; info#business01.com; other#business01.com; email#business01.com; other#business01.com; other#business01.com; email#business01.com;
Business Name 02 email#business02.com; info#business02.com; other#business02.com; email#business02.com; email#business02.com; other#business02.com; other#business02.com; info#business02.com; email#business02.com; info#business02.com; other#business02.com;
I am looking to delete the duplicate addresses. So the list should look like:
Business Name 01 email#business01.com; other#business01.com; info#business01.com;
Business Name 02 email#business02.com; info#business02.com; other#business02.com;
This has me stumped. Any ideas?

Related

concept of domains and subdomains for small database entities

recently I learned a concept called by my teacher "Domains and subdomains" in which small tables are generalized in which less than 5000 data or rows will be saved, I show you an example:
Entities
enter image description here
level dates:
id_level description
01 continent
02 country
03 state
domain dates
id_domain detail level parent
01 America 01 -
02 USA 02 01
03 Europe 01 -
04 Africa 01 -
05 UK 02 03
06 Aberdeen 03 05
If this concept has another name, it would help me a lot to know it.
Then we had to make an abstraction of this and take it to common entities like the following example:
enter image description here
level dates:
id_level description
01 address
02 phone
03 gender
domain dates
id_domain detail level parent
01 male 03 -
02 female 03 -
03 mobile phone 02 -
04 home address 01 -
05 home phone 02 -
06 work address 01 -
Person dates
id_person name phone_type phone_value address_type adress_value gender
01 Jhon 03 39249927 06 a place... 01
02 Mary 05 2489540300 04 a place2... 02
but i get an error saying, the duplicate key name when i try to make the relation
ALTER TABLE person
ADD CONSTRAINT FK_PERSON_DOMAIN
FOREIGN KEY (address_type)
REFERENCES domain(id_domain);
Error
Duplicate key name 'FK_PERSON_DOMAIN'
Something I should add is that I already did the nesting with phone_type, after this it does not let me nest the other two attributes as shown in the diagram
This is the relationship that worked perfectly:
ALTER TABLE person
ADD CONSTRAINT FK_PERSON_DOMAIN
FOREIGN KEY (phone_type)
REFERENCES domain(id_domain);
I call those "lookup tables." They usually have characteristics of having a small number of rows, and also they don't change frequently. They may have an integer id primary key, or they may have a natural primary key.
The error you got about the duplicate key name is caused by the rule that constraint names must be unique across all tables in a schema. In other words, there must be only one constraint named FK_PERSON_DOMAIN_PERSON in the schema.
You said you already created a constraint with this name for the phone_type column. If you want another constraint for the address_type column, you must choose a different name for that constraint.
Here's an example of what I mean:
ALTER TABLE person
ADD CONSTRAINT FK_PERSON_PHONE
FOREIGN KEY (phone_type)
REFERENCES domain(id_domain);
ALTER TABLE person
ADD CONSTRAINT FK_PERSON_ADDRESS
FOREIGN KEY (address_type)
REFERENCES domain(id_domain);
See that the constraint names are different.

Getting in a muddle with numeric primary keys

I hope someone can help. I'm trying to set up something along the below but am getting in a bit of a muddle. From what I understand, deriving a numeric ID variable (eg auto-incremented) for the primary key is more efficient that using a composite primary key of the 'natural' variables that define a record (especially if they're character variables (and more so if the collation is UTF-8))
As in the below example, each customer has a list of items (ITEMID) which are all members of a category (CATID), however, the problem is that I need customers to additionally be able to assign their items as a component of a collection set (SETID) which is a non-identifying reference table - any customer could have multiple versions of one SETID.
The items required for a set are specified by CATID. Therefore, in the example below which is for one customer, they could choose to assign Item 2, or 4 (or neither or both) to SET 001.
**ITEMS**
ITEMID CATID
1 04
2 02
3 01
4 02
5 05
**SETS**
SETID CATID
001 01
001 02
002 04
003 05
**CATEGORY**
CATID
01
02
03
04
05
**Wanted result:**
ITEMID CATID SETNUMBER SETID
1 04 (customer chose not to assign to SET 002)
2 02 1 001
3 01 1 001
4 02 2 001
5 05 003
Many thanks in advance!
From your description, it sounds like the "ITEM" table could stand to have a NULLable "SETID" foreign-key column.

SQL: Aggregate function returning 0's when using WHERE filter

I have a table with 10 columns listing results of a marketing campaign including person name, date, residence area, request, and response.
The request column is always a number, indicating the number of survey requests we've sent a specific person.
The response column is a number from 0 to X, representing the number of surveys a person has responded to take.
Now, when I look through the actual table, there are probably around 10% response rate. With lots of non-zero entries in the response column.
However, when I write an aggregate function like this:
SELECT person, date, SUM(requests), SUM(response)
FROM analytics.SurveyResults0304
WHERE group_type = 'Youth'
GROUP BY person, date;
I get a correct number for SUM(requests), but I get a big fat "0" for SUM(response)?
It's the same for all 3 group types. It returns a 0 for SUM(response)
Update: it works fine when I don't include the group_type filter, but how come I can't use it with the WHERE filter?
Thanks!!!
EDIT2: Sample Table
Person Date Group_Type Requests Response Neighborhood FirstName
-------- -------- ----------- -------- -------- ------------ ---------
Nixon 3/3/2013 Youth 3 3 Chinatown Richard
Clinton 3/3/2013 Youth 4 0 Gunhill Bill
Mao 3/3/2013 Youth 5 0 Berryville Chairman
Nixon 3/4/2013 Youth 17 2 Townsford Richard
Gates 3/3/2013 Elderly 41 5 Chinatown Bill
Gates 3/4/2013 Elderly 0 0 Chinatown Bill
Gates 3/5/2013 Elderly 0 0 Chinatown Bill
Gates 3/6/2013 Elderly 0 0 Chinatown Bill
For example
When I do:
SELECT SUM(requests), SUM(response)
FROM analytics.SurveyResults0304
WHERE group_type = 'Youth';
It returns 70 for request, and 0 for response across the board.
Your code seems to be working. See SQL Fiddle built from your data sample.
May be you have extra spaces and/or tabs in your Group_Type column?
PERSON DATE SUM(REQUESTS) SUM(RESPONSE)
--------------------------------------------------------
Clinton March, 03 2013 00:00:00+0000 4 0
Mao March, 03 2013 00:00:00+0000 5 0
Nixon March, 03 2013 00:00:00+0000 3 3
Nixon March, 04 2013 00:00:00+0000 17 2

Dynamic Columns In Reporting Services Tablix

I have a data query that returns data in the following format:
Name Period Value
-----------------------------
Bob Jan 123
Bob Feb 456
Bob Mar 789
Tom Jan 321
Tom Feb 654
Tom Mar 987
Joe Jan 147
Joe Feb 258
Joe Mar 369
The different periods are constant between names, but will be different between executions of the report (ie, I may query a report on Jan/Feb/Mar now, or Apr/May/Jun later). I'm trying to put that into a table in my Reporting Services report, that would look something like this:
Name Jan Feb Mar
----------------------------
Bob 123 456 789
Tom 321 654 987
Joe 147 258 369
Can anyone point me to an example of doing something like that? I'm not even sure how to describe that 'rotation'(?) of the data. The columns should be dynamic based on what Period values are in the dataset.
Found the answer right after posting. Here's what I did.
Created a new Tablix. Dragged the Name field to the data row of the first column. Dragged the Value column to the data row of the second column. Dragged the Period field to the header row of the second column. That created a new group, and a new second level header column. I then copied the value from that new top header column to the header cell below it, and deleted the whole new header row. When asked whether to delete the row and associated groups, or just row, choose just the row. You should be left with a Row Group and two Column Groups, and it should render as intended.

How to display a table order by code (like 01, 02… then null columns)?

How to display a table order by code (like 01, 02… then null columns)?
Using Access 2003 Database
Table
Name Title code Nationality code
Raja 05 03
Ramu 03
Vijay 01 02
John 04 01
Roby 06
Abilash 02 05
So on…,
I want to display a table order by title code, nationality code
In my “nationality code” field some of the columns are null, so I want to display a table order by title code, nationality code (like 01, 02… then null columns)
My query.
Select * from table order by nationality code, title code
Name Title Nationality
Ramu 03
Roby 06
John 04 01
Vijay 01 02
Raja 05 03
Abilash 02 05
But Null value is coming first in the nationality code, I want to display nationality code like 01, 02, 03, 05 then null values
Need Query Help.
Try using the Nz function to provide a value for NULL columns, for example ORDER BY Nz(Nationality,9999999)
Note the NZ() will only work within the Access user interface. For a more neutral approach, you could try an expression in the ORDER BY clause e.g. something like
ORDER BY (LEN(nationality_code) > 0), nationality_code, title_code;
Are you sure those values are NULL rather than zero-length values? If they are, then you should replace them with NULL then set Allow Zero Length to false for the column or add a Validation Rule or CHECK constraint to do the same.
If they are NULL then this may be a bug. I assume you are using Jet 4.0, for which NULL collation should sort NULL to the end of the resultset. In which case, you need the workaround (i.e. currently selected answer).
A note on Nulls/ZLS: Access 2003 (or maybe it was 2002, which I barely ever used) changed the default in its table designer from AllowZLS: No to AllowZLS: Yes. It's very, very annoying.