table 1
APP_ID
1
3
table 2
APP_ID Profile_NUM
1 001AAA
2 001AAA
3 001AAA
1 000A223
2 000A223
1 01A345
2 01A345
1 0909
3 0909
5 BASS1
6 BASS1
7 BASS1
I would Like to perform the following:
. read table 1
. match table 1 against table 2, using App_ID column, and return
the following Profile_Num from table 2:
. 0909 - exact match
. 001AAA - close matches
. 000A223 - close match
. 01A345 - close match
THANKS!
(POSTED AGAIN FOR CORRECTION) 7 1832
> I would Like to perform the following: . read table 1 . match table 1 against table 2, using App_ID column, and return the following Profile_Num from table 2: . 0909 - exact match . 001AAA - close matches . 000A223 - close match . 01A345 - close match
I'm not sure I understand your match criteria. The example below may be
part of a solution though.
CREATE TABLE Table1
(
APP_ID int NOT NULL
CONSTRAINT PK_Table1 PRIMARY KEY,
)
CREATE TABLE Table2
(
APP_ID int NOT NULL,
Profile_NUM varchar(10) NOT NULL,
CONSTRAINT PK_Table2 PRIMARY KEY(APP_ID,Profile_NUM)
)
INSERT INTO Table1
SELECT 1 UNION ALL
SELECT 3
INSERT INTO Table2
SELECT 1, '001AAA' UNION ALL
SELECT 2, '001AAA' UNION ALL
SELECT 3, '001AAA' UNION ALL
SELECT 1, '000A223' UNION ALL
SELECT 2, '000A223' UNION ALL
SELECT 1, '01A345' UNION ALL
SELECT 2, '01A345' UNION ALL
SELECT 1, '0909' UNION ALL
SELECT 3, '0909' UNION ALL
SELECT 5, 'BASS1' UNION ALL
SELECT 6, 'BASS1' UNION ALL
SELECT 7, 'BASS1'
SELECT DISTINCT
MatchingProfiles.Profile_NUM,
CASE
WHEN MatchingProfiles.ProfileCount = AllProfiles.ProfileCount
THEN 'exact match'
WHEN MatchingProfiles.ProfileCount = (SELECT COUNT(*) FROM Table1)
THEN 'close matches'
ELSE 'close match' END
FROM
(
SELECT Profile_NUM, COUNT(*) AS ProfileCount
FROM Table2
GROUP BY Profile_NUM
) AS AllProfiles
JOIN
(
SELECT Profile_NUM, COUNT(*) AS ProfileCount
FROM Table1 t1
JOIN Table2 t2 ON
t1.APP_ID = t2.APP_ID
GROUP BY Profile_NUM
) AS MatchingProfiles ON
AllProfiles.Profile_NUM = MatchingProfiles.Profile_NUM
--
Hope this helps.
Dan Guzman
SQL Server MVP
"OBJECT MODULE, INC." <gr*********@yahoo.com> wrote in message
news:99**************************@posting.google.c om... table 1
APP_ID 1 3 table 2
APP_ID Profile_NUM 1 001AAA 2 001AAA 3 001AAA 1 000A223 2 000A223 1 01A345 2 01A345 1 0909 3 0909 5 BASS1 6 BASS1 7 BASS1
I would Like to perform the following: . read table 1 . match table 1 against table 2, using App_ID column, and return the following Profile_Num from table 2: . 0909 - exact match . 001AAA - close matches . 000A223 - close match . 01A345 - close match
THANKS!
(POSTED AGAIN FOR CORRECTION)
Dan, tks. I will study this code and see if it's doable.
"Dan Guzman" <da*******@nospam-earthlink.net> wrote in message news:<de*************@newsread1.news.atl.earthlink .net>... I would Like to perform the following: . read table 1 . match table 1 against table 2, using App_ID column, and return the following Profile_Num from table 2: . 0909 - exact match . 001AAA - close matches . 000A223 - close match . 01A345 - close match
I'm not sure I understand your match criteria. The example below may be part of a solution though.
CREATE TABLE Table1 ( APP_ID int NOT NULL CONSTRAINT PK_Table1 PRIMARY KEY, )
CREATE TABLE Table2 ( APP_ID int NOT NULL, Profile_NUM varchar(10) NOT NULL, CONSTRAINT PK_Table2 PRIMARY KEY(APP_ID,Profile_NUM) )
INSERT INTO Table1 SELECT 1 UNION ALL SELECT 3
INSERT INTO Table2 SELECT 1, '001AAA' UNION ALL SELECT 2, '001AAA' UNION ALL SELECT 3, '001AAA' UNION ALL SELECT 1, '000A223' UNION ALL SELECT 2, '000A223' UNION ALL SELECT 1, '01A345' UNION ALL SELECT 2, '01A345' UNION ALL SELECT 1, '0909' UNION ALL SELECT 3, '0909' UNION ALL SELECT 5, 'BASS1' UNION ALL SELECT 6, 'BASS1' UNION ALL SELECT 7, 'BASS1'
SELECT DISTINCT MatchingProfiles.Profile_NUM, CASE WHEN MatchingProfiles.ProfileCount = AllProfiles.ProfileCount THEN 'exact match' WHEN MatchingProfiles.ProfileCount = (SELECT COUNT(*) FROM Table1) THEN 'close matches' ELSE 'close match' END FROM ( SELECT Profile_NUM, COUNT(*) AS ProfileCount FROM Table2 GROUP BY Profile_NUM ) AS AllProfiles JOIN ( SELECT Profile_NUM, COUNT(*) AS ProfileCount FROM Table1 t1 JOIN Table2 t2 ON t1.APP_ID = t2.APP_ID GROUP BY Profile_NUM ) AS MatchingProfiles ON AllProfiles.Profile_NUM = MatchingProfiles.Profile_NUM
-- Hope this helps.
Dan Guzman SQL Server MVP "OBJECT MODULE, INC." <gr*********@yahoo.com> wrote in message news:99**************************@posting.google.c om... table 1
APP_ID 1 3 table 2
APP_ID Profile_NUM 1 001AAA 2 001AAA 3 001AAA 1 000A223 2 000A223 1 01A345 2 01A345 1 0909 3 0909 5 BASS1 6 BASS1 7 BASS1
I would Like to perform the following: . read table 1 . match table 1 against table 2, using App_ID column, and return the following Profile_Num from table 2: . 0909 - exact match . 001AAA - close matches . 000A223 - close match . 01A345 - close match
THANKS!
(POSTED AGAIN FOR CORRECTION)
could not quite the result. let's try this again:
Table 1
ID
1
3
TABLE 2
ID PROFILE_NUM
1 AA1
1 AA2
1 AA3
1 AA7
2 AA2
2 AA3
3 AA1
3 AA2
3 AA7
4 AA9
4 AA8
WOULD TO TO SEE THIS RESULT:
AA1 - Exact Match
AA2 - Close Match
AA3 - Close Match
AA7 - Exact Match g2**********@yahoo.com (OBJECT MODULE, INC.) wrote in message ne3ws:<99**************************@posting.google .com>... Dan, tks. I will study this code and see if it's doable. "Dan Guzman" <da*******@nospam-earthlink.net> wrote in message news:<de*************@newsread1.news.atl.earthlink .net>... I would Like to perform the following: . read table 1 . match table 1 against table 2, using App_ID column, and return the following Profile_Num from table 2: . 0909 - exact match . 001AAA - close matches . 000A223 - close match . 01A345 - close match
I'm not sure I understand your match criteria. The example below may be part of a solution though.
CREATE TABLE Table1 ( APP_ID int NOT NULL CONSTRAINT PK_Table1 PRIMARY KEY, )
CREATE TABLE Table2 ( APP_ID int NOT NULL, Profile_NUM varchar(10) NOT NULL, CONSTRAINT PK_Table2 PRIMARY KEY(APP_ID,Profile_NUM) )
INSERT INTO Table1 SELECT 1 UNION ALL SELECT 3
INSERT INTO Table2 SELECT 1, '001AAA' UNION ALL SELECT 2, '001AAA' UNION ALL SELECT 3, '001AAA' UNION ALL SELECT 1, '000A223' UNION ALL SELECT 2, '000A223' UNION ALL SELECT 1, '01A345' UNION ALL SELECT 2, '01A345' UNION ALL SELECT 1, '0909' UNION ALL SELECT 3, '0909' UNION ALL SELECT 5, 'BASS1' UNION ALL SELECT 6, 'BASS1' UNION ALL SELECT 7, 'BASS1'
SELECT DISTINCT MatchingProfiles.Profile_NUM, CASE WHEN MatchingProfiles.ProfileCount = AllProfiles.ProfileCount THEN 'exact match' WHEN MatchingProfiles.ProfileCount = (SELECT COUNT(*) FROM Table1) THEN 'close matches' ELSE 'close match' END FROM ( SELECT Profile_NUM, COUNT(*) AS ProfileCount FROM Table2 GROUP BY Profile_NUM ) AS AllProfiles JOIN ( SELECT Profile_NUM, COUNT(*) AS ProfileCount FROM Table1 t1 JOIN Table2 t2 ON t1.APP_ID = t2.APP_ID GROUP BY Profile_NUM ) AS MatchingProfiles ON AllProfiles.Profile_NUM = MatchingProfiles.Profile_NUM
-- Hope this helps.
Dan Guzman SQL Server MVP "OBJECT MODULE, INC." <gr*********@yahoo.com> wrote in message news:99**************************@posting.google.c om... table 1
APP_ID 1 3 table 2
APP_ID Profile_NUM 1 001AAA 2 001AAA 3 001AAA 1 000A223 2 000A223 1 01A345 2 01A345 1 0909 3 0909 5 BASS1 6 BASS1 7 BASS1
I would Like to perform the following: . read table 1 . match table 1 against table 2, using App_ID column, and return the following Profile_Num from table 2: . 0909 - exact match . 001AAA - close matches . 000A223 - close match . 01A345 - close match
THANKS!
(POSTED AGAIN FOR CORRECTION)
Try:
SELECT
MatchingProfiles.Profile_NUM,
CASE
WHEN MatchingProfiles.ProfileCount = AllProfiles.ProfileCount
THEN 'exact match'
ELSE 'close match' END
FROM
(
SELECT Profile_NUM, COUNT(*) AS ProfileCount
FROM Table2
GROUP BY Profile_NUM
) AS AllProfiles
JOIN
(
SELECT Profile_NUM, COUNT(*) AS ProfileCount
FROM Table1 t1
JOIN Table2 t2 ON
t1.APP_ID = t2.APP_ID
GROUP BY Profile_NUM
) AS MatchingProfiles ON
AllProfiles.Profile_NUM = MatchingProfiles.Profile_NUM
--
Hope this helps.
Dan Guzman
SQL Server MVP
"OBJECT MODULE, INC." <gr*********@yahoo.com> wrote in message
news:99**************************@posting.google.c om... could not quite the result. let's try this again:
Table 1 ID 1 3
TABLE 2 ID PROFILE_NUM 1 AA1 1 AA2 1 AA3 1 AA7 2 AA2 2 AA3 3 AA1 3 AA2 3 AA7 4 AA9 4 AA8 WOULD TO TO SEE THIS RESULT: AA1 - Exact Match AA2 - Close Match AA3 - Close Match AA7 - Exact Match g2**********@yahoo.com (OBJECT MODULE, INC.) wrote in message
ne3ws:<99**************************@posting.google .com>... Dan, tks. I will study this code and see if it's doable. "Dan Guzman" <da*******@nospam-earthlink.net> wrote in message
news:<de*************@newsread1.news.atl.earthlink .net>... > I would Like to perform the following: > . read table 1 > . match table 1 against table 2, using App_ID column, and return > the following Profile_Num from table 2: > . 0909 - exact match > . 001AAA - close matches > . 000A223 - close match > . 01A345 - close match
I'm not sure I understand your match criteria. The example below may
be part of a solution though.
CREATE TABLE Table1 ( APP_ID int NOT NULL CONSTRAINT PK_Table1 PRIMARY KEY, )
CREATE TABLE Table2 ( APP_ID int NOT NULL, Profile_NUM varchar(10) NOT NULL, CONSTRAINT PK_Table2 PRIMARY KEY(APP_ID,Profile_NUM) )
INSERT INTO Table1 SELECT 1 UNION ALL SELECT 3
INSERT INTO Table2 SELECT 1, '001AAA' UNION ALL SELECT 2, '001AAA' UNION ALL SELECT 3, '001AAA' UNION ALL SELECT 1, '000A223' UNION ALL SELECT 2, '000A223' UNION ALL SELECT 1, '01A345' UNION ALL SELECT 2, '01A345' UNION ALL SELECT 1, '0909' UNION ALL SELECT 3, '0909' UNION ALL SELECT 5, 'BASS1' UNION ALL SELECT 6, 'BASS1' UNION ALL SELECT 7, 'BASS1'
SELECT DISTINCT MatchingProfiles.Profile_NUM, CASE WHEN MatchingProfiles.ProfileCount = AllProfiles.ProfileCount THEN 'exact match' WHEN MatchingProfiles.ProfileCount = (SELECT COUNT(*) FROM
Table1) THEN 'close matches' ELSE 'close match' END FROM ( SELECT Profile_NUM, COUNT(*) AS ProfileCount FROM Table2 GROUP BY Profile_NUM ) AS AllProfiles JOIN ( SELECT Profile_NUM, COUNT(*) AS ProfileCount FROM Table1 t1 JOIN Table2 t2 ON t1.APP_ID = t2.APP_ID GROUP BY Profile_NUM ) AS MatchingProfiles ON AllProfiles.Profile_NUM = MatchingProfiles.Profile_NUM
-- Hope this helps.
Dan Guzman SQL Server MVP "OBJECT MODULE, INC." <gr*********@yahoo.com> wrote in message news:99**************************@posting.google.c om... > table 1 > > APP_ID > 1 > 3 > > > > table 2 > > APP_ID Profile_NUM > 1 001AAA > 2 001AAA > 3 001AAA > 1 000A223 > 2 000A223 > 1 01A345 > 2 01A345 > 1 0909 > 3 0909 > 5 BASS1 > 6 BASS1 > 7 BASS1 > > > > > I would Like to perform the following: > . read table 1 > . match table 1 against table 2, using App_ID column, and return > the following Profile_Num from table 2: > . 0909 - exact match > . 001AAA - close matches > . 000A223 - close match > . 01A345 - close match > > THANKS! > > (POSTED AGAIN FOR CORRECTION)
Worked like an expert. Thanks Dan!
"Dan Guzman" <da*******@nospam-earthlink.net> wrote in message news:<0e***************@newsread1.news.atl.earthli nk.net>... Try:
SELECT MatchingProfiles.Profile_NUM, CASE WHEN MatchingProfiles.ProfileCount = AllProfiles.ProfileCount THEN 'exact match' ELSE 'close match' END FROM ( SELECT Profile_NUM, COUNT(*) AS ProfileCount FROM Table2 GROUP BY Profile_NUM ) AS AllProfiles JOIN ( SELECT Profile_NUM, COUNT(*) AS ProfileCount FROM Table1 t1 JOIN Table2 t2 ON t1.APP_ID = t2.APP_ID GROUP BY Profile_NUM ) AS MatchingProfiles ON AllProfiles.Profile_NUM = MatchingProfiles.Profile_NUM
-- Hope this helps.
Dan Guzman SQL Server MVP
"OBJECT MODULE, INC." <gr*********@yahoo.com> wrote in message news:99**************************@posting.google.c om... could not quite the result. let's try this again:
Table 1 ID 1 3
TABLE 2 ID PROFILE_NUM 1 AA1 1 AA2 1 AA3 1 AA7 2 AA2 2 AA3 3 AA1 3 AA2 3 AA7 4 AA9 4 AA8 WOULD TO TO SEE THIS RESULT: AA1 - Exact Match AA2 - Close Match AA3 - Close Match AA7 - Exact Match g2**********@yahoo.com (OBJECT MODULE, INC.) wrote in message ne3ws:<99**************************@posting.google .com>... Dan, tks. I will study this code and see if it's doable. "Dan Guzman" <da*******@nospam-earthlink.net> wrote in message news:<de*************@newsread1.news.atl.earthlink .net>... > > I would Like to perform the following: > > . read table 1 > > . match table 1 against table 2, using App_ID column, and return > > the following Profile_Num from table 2: > > . 0909 - exact match > > . 001AAA - close matches > > . 000A223 - close match > > . 01A345 - close match > > I'm not sure I understand your match criteria. The example below may be > part of a solution though. > > CREATE TABLE Table1 > ( > APP_ID int NOT NULL > CONSTRAINT PK_Table1 PRIMARY KEY, > ) > > CREATE TABLE Table2 > ( > APP_ID int NOT NULL, > Profile_NUM varchar(10) NOT NULL, > CONSTRAINT PK_Table2 PRIMARY KEY(APP_ID,Profile_NUM) > ) > > INSERT INTO Table1 > SELECT 1 UNION ALL > SELECT 3 > > INSERT INTO Table2 > SELECT 1, '001AAA' UNION ALL > SELECT 2, '001AAA' UNION ALL > SELECT 3, '001AAA' UNION ALL > SELECT 1, '000A223' UNION ALL > SELECT 2, '000A223' UNION ALL > SELECT 1, '01A345' UNION ALL > SELECT 2, '01A345' UNION ALL > SELECT 1, '0909' UNION ALL > SELECT 3, '0909' UNION ALL > SELECT 5, 'BASS1' UNION ALL > SELECT 6, 'BASS1' UNION ALL > SELECT 7, 'BASS1' > > SELECT DISTINCT > MatchingProfiles.Profile_NUM, > CASE > WHEN MatchingProfiles.ProfileCount = AllProfiles.ProfileCount > THEN 'exact match' > WHEN MatchingProfiles.ProfileCount = (SELECT COUNT(*) FROM Table1) > THEN 'close matches' > ELSE 'close match' END > FROM > ( > SELECT Profile_NUM, COUNT(*) AS ProfileCount > FROM Table2 > GROUP BY Profile_NUM > ) AS AllProfiles > JOIN > ( > SELECT Profile_NUM, COUNT(*) AS ProfileCount > FROM Table1 t1 > JOIN Table2 t2 ON > t1.APP_ID = t2.APP_ID > GROUP BY Profile_NUM > ) AS MatchingProfiles ON > AllProfiles.Profile_NUM = MatchingProfiles.Profile_NUM > > -- > Hope this helps. > > Dan Guzman > SQL Server MVP > > > > "OBJECT MODULE, INC." <gr*********@yahoo.com> wrote in message > news:99**************************@posting.google.c om... > > table 1 > > > > APP_ID > > 1 > > 3 > > > > > > > > table 2 > > > > APP_ID Profile_NUM > > 1 001AAA > > 2 001AAA > > 3 001AAA > > 1 000A223 > > 2 000A223 > > 1 01A345 > > 2 01A345 > > 1 0909 > > 3 0909 > > 5 BASS1 > > 6 BASS1 > > 7 BASS1 > > > > > > > > > > I would Like to perform the following: > > . read table 1 > > . match table 1 against table 2, using App_ID column, and return > > the following Profile_Num from table 2: > > . 0909 - exact match > > . 001AAA - close matches > > . 000A223 - close match > > . 01A345 - close match > > > > THANKS! > > > > (POSTED AGAIN FOR CORRECTION)
"Dan Guzman" <da*******@nospam-earthlink.net> wrote in message
news:0e***************@newsread1.news.atl.earthlin k.net... Try:
SELECT MatchingProfiles.Profile_NUM, CASE WHEN MatchingProfiles.ProfileCount = AllProfiles.ProfileCount THEN 'exact match' ELSE 'close match' END FROM ( SELECT Profile_NUM, COUNT(*) AS ProfileCount FROM Table2 GROUP BY Profile_NUM ) AS AllProfiles JOIN ( SELECT Profile_NUM, COUNT(*) AS ProfileCount FROM Table1 t1 JOIN Table2 t2 ON t1.APP_ID = t2.APP_ID GROUP BY Profile_NUM ) AS MatchingProfiles ON AllProfiles.Profile_NUM = MatchingProfiles.Profile_NUM
Dan, please note that you have to additionally check that
AllProfiles.ProfileCount = (SELECT COUNT(*) FROM Table1)
when testing for an exact match. For example, given the sample data,
if AA7 is only associated with 1 or 3, but not both and with no other id,
then it should not be an exact match but a close match.
Regards,
jag
-- Hope this helps.
Dan Guzman SQL Server MVP
"OBJECT MODULE, INC." <gr*********@yahoo.com> wrote in message news:99**************************@posting.google.c om... could not quite the result. let's try this again:
Table 1 ID 1 3
TABLE 2 ID PROFILE_NUM 1 AA1 1 AA2 1 AA3 1 AA7 2 AA2 2 AA3 3 AA1 3 AA2 3 AA7 4 AA9 4 AA8 WOULD TO TO SEE THIS RESULT: AA1 - Exact Match AA2 - Close Match AA3 - Close Match AA7 - Exact Match g2**********@yahoo.com (OBJECT MODULE, INC.) wrote in message ne3ws:<99**************************@posting.google .com>... Dan, tks. I will study this code and see if it's doable. "Dan Guzman" <da*******@nospam-earthlink.net> wrote in message news:<de*************@newsread1.news.atl.earthlink .net>... > > I would Like to perform the following: > > . read table 1 > > . match table 1 against table 2, using App_ID column, and return > > the following Profile_Num from table 2: > > . 0909 - exact match > > . 001AAA - close matches > > . 000A223 - close match > > . 01A345 - close match > > I'm not sure I understand your match criteria. The example below may be > part of a solution though. > > CREATE TABLE Table1 > ( > APP_ID int NOT NULL > CONSTRAINT PK_Table1 PRIMARY KEY, > ) > > CREATE TABLE Table2 > ( > APP_ID int NOT NULL, > Profile_NUM varchar(10) NOT NULL, > CONSTRAINT PK_Table2 PRIMARY KEY(APP_ID,Profile_NUM) > ) > > INSERT INTO Table1 > SELECT 1 UNION ALL > SELECT 3 > > INSERT INTO Table2 > SELECT 1, '001AAA' UNION ALL > SELECT 2, '001AAA' UNION ALL > SELECT 3, '001AAA' UNION ALL > SELECT 1, '000A223' UNION ALL > SELECT 2, '000A223' UNION ALL > SELECT 1, '01A345' UNION ALL > SELECT 2, '01A345' UNION ALL > SELECT 1, '0909' UNION ALL > SELECT 3, '0909' UNION ALL > SELECT 5, 'BASS1' UNION ALL > SELECT 6, 'BASS1' UNION ALL > SELECT 7, 'BASS1' > > SELECT DISTINCT > MatchingProfiles.Profile_NUM, > CASE > WHEN MatchingProfiles.ProfileCount = AllProfiles.ProfileCount > THEN 'exact match' > WHEN MatchingProfiles.ProfileCount = (SELECT COUNT(*) FROM Table1) > THEN 'close matches' > ELSE 'close match' END > FROM > ( > SELECT Profile_NUM, COUNT(*) AS ProfileCount > FROM Table2 > GROUP BY Profile_NUM > ) AS AllProfiles > JOIN > ( > SELECT Profile_NUM, COUNT(*) AS ProfileCount > FROM Table1 t1 > JOIN Table2 t2 ON > t1.APP_ID = t2.APP_ID > GROUP BY Profile_NUM > ) AS MatchingProfiles ON > AllProfiles.Profile_NUM = MatchingProfiles.Profile_NUM > > -- > Hope this helps. > > Dan Guzman > SQL Server MVP > > > > "OBJECT MODULE, INC." <gr*********@yahoo.com> wrote in message > news:99**************************@posting.google.c om... > > table 1 > > > > APP_ID > > 1 > > 3 > > > > > > > > table 2 > > > > APP_ID Profile_NUM > > 1 001AAA > > 2 001AAA > > 3 001AAA > > 1 000A223 > > 2 000A223 > > 1 01A345 > > 2 01A345 > > 1 0909 > > 3 0909 > > 5 BASS1 > > 6 BASS1 > > 7 BASS1 > > > > > > > > > > I would Like to perform the following: > > . read table 1 > > . match table 1 against table 2, using App_ID column, and return > > the following Profile_Num from table 2: > > . 0909 - exact match > > . 001AAA - close matches > > . 000A223 - close match > > . 01A345 - close match > > > > THANKS! > > > > (POSTED AGAIN FOR CORRECTION)
> Dan, please note that you have to additionally check that AllProfiles.ProfileCount = (SELECT COUNT(*) FROM Table1) when testing for an exact match. For example, given the sample data, if AA7 is only associated with 1 or 3, but not both and with no other id, then it should not be an exact match but a close match.
Thanks for catching this, John. I only tested with the provided sample data
and didn't notice that all conditions weren't tested.
SELECT
MatchingProfiles.Profile_NUM,
CASE
WHEN MatchingProfiles.ProfileCount = AllProfiles.ProfileCount AND
AllProfiles.ProfileCount = (SELECT COUNT(*) FROM Table1)
THEN 'exact match'
ELSE 'close match' END
FROM
(
SELECT Profile_NUM, COUNT(*) AS ProfileCount
FROM Table2
GROUP BY Profile_NUM
) AS AllProfiles
JOIN
(
SELECT Profile_NUM, COUNT(*) AS ProfileCount
FROM Table1 t1
JOIN Table2 t2 ON
t1.APP_ID = t2.APP_ID
GROUP BY Profile_NUM
) AS MatchingProfiles ON
AllProfiles.Profile_NUM = MatchingProfiles.Profile_NUM
--
Hope this helps.
Dan Guzman
SQL Server MVP
"John Gilson" <ja*@acm.org> wrote in message
news:sW*********************@twister.nyc.rr.com... "Dan Guzman" <da*******@nospam-earthlink.net> wrote in message news:0e***************@newsread1.news.atl.earthlin k.net... Try:
SELECT MatchingProfiles.Profile_NUM, CASE WHEN MatchingProfiles.ProfileCount = AllProfiles.ProfileCount THEN 'exact match' ELSE 'close match' END FROM ( SELECT Profile_NUM, COUNT(*) AS ProfileCount FROM Table2 GROUP BY Profile_NUM ) AS AllProfiles JOIN ( SELECT Profile_NUM, COUNT(*) AS ProfileCount FROM Table1 t1 JOIN Table2 t2 ON t1.APP_ID = t2.APP_ID GROUP BY Profile_NUM ) AS MatchingProfiles ON AllProfiles.Profile_NUM = MatchingProfiles.Profile_NUM
Dan, please note that you have to additionally check that AllProfiles.ProfileCount = (SELECT COUNT(*) FROM Table1) when testing for an exact match. For example, given the sample data, if AA7 is only associated with 1 or 3, but not both and with no other id, then it should not be an exact match but a close match.
Regards, jag
-- Hope this helps.
Dan Guzman SQL Server MVP
"OBJECT MODULE, INC." <gr*********@yahoo.com> wrote in message news:99**************************@posting.google.c om... could not quite the result. let's try this again:
Table 1 ID 1 3
TABLE 2 ID PROFILE_NUM 1 AA1 1 AA2 1 AA3 1 AA7 2 AA2 2 AA3 3 AA1 3 AA2 3 AA7 4 AA9 4 AA8 WOULD TO TO SEE THIS RESULT: AA1 - Exact Match AA2 - Close Match AA3 - Close Match AA7 - Exact Match g2**********@yahoo.com (OBJECT MODULE, INC.) wrote in message ne3ws:<99**************************@posting.google .com>... > Dan, tks. I will study this code and see if it's doable. > > > > "Dan Guzman" <da*******@nospam-earthlink.net> wrote in message news:<de*************@newsread1.news.atl.earthlink .net>... > > > I would Like to perform the following: > > > . read table 1 > > > . match table 1 against table 2, using App_ID column, and return > > > the following Profile_Num from table 2: > > > . 0909 - exact match > > > . 001AAA - close matches > > > . 000A223 - close match > > > . 01A345 - close match > > > > I'm not sure I understand your match criteria. The example below
may be > > part of a solution though. > > > > CREATE TABLE Table1 > > ( > > APP_ID int NOT NULL > > CONSTRAINT PK_Table1 PRIMARY KEY, > > ) > > > > CREATE TABLE Table2 > > ( > > APP_ID int NOT NULL, > > Profile_NUM varchar(10) NOT NULL, > > CONSTRAINT PK_Table2 PRIMARY KEY(APP_ID,Profile_NUM) > > ) > > > > INSERT INTO Table1 > > SELECT 1 UNION ALL > > SELECT 3 > > > > INSERT INTO Table2 > > SELECT 1, '001AAA' UNION ALL > > SELECT 2, '001AAA' UNION ALL > > SELECT 3, '001AAA' UNION ALL > > SELECT 1, '000A223' UNION ALL > > SELECT 2, '000A223' UNION ALL > > SELECT 1, '01A345' UNION ALL > > SELECT 2, '01A345' UNION ALL > > SELECT 1, '0909' UNION ALL > > SELECT 3, '0909' UNION ALL > > SELECT 5, 'BASS1' UNION ALL > > SELECT 6, 'BASS1' UNION ALL > > SELECT 7, 'BASS1' > > > > SELECT DISTINCT > > MatchingProfiles.Profile_NUM, > > CASE > > WHEN MatchingProfiles.ProfileCount =
AllProfiles.ProfileCount > > THEN 'exact match' > > WHEN MatchingProfiles.ProfileCount = (SELECT COUNT(*) FROM Table1) > > THEN 'close matches' > > ELSE 'close match' END > > FROM > > ( > > SELECT Profile_NUM, COUNT(*) AS ProfileCount > > FROM Table2 > > GROUP BY Profile_NUM > > ) AS AllProfiles > > JOIN > > ( > > SELECT Profile_NUM, COUNT(*) AS ProfileCount > > FROM Table1 t1 > > JOIN Table2 t2 ON > > t1.APP_ID = t2.APP_ID > > GROUP BY Profile_NUM > > ) AS MatchingProfiles ON > > AllProfiles.Profile_NUM = MatchingProfiles.Profile_NUM > > > > -- > > Hope this helps. > > > > Dan Guzman > > SQL Server MVP > > > > > > > > "OBJECT MODULE, INC." <gr*********@yahoo.com> wrote in message > > news:99**************************@posting.google.c om... > > > table 1 > > > > > > APP_ID > > > 1 > > > 3 > > > > > > > > > > > > table 2 > > > > > > APP_ID Profile_NUM > > > 1 001AAA > > > 2 001AAA > > > 3 001AAA > > > 1 000A223 > > > 2 000A223 > > > 1 01A345 > > > 2 01A345 > > > 1 0909 > > > 3 0909 > > > 5 BASS1 > > > 6 BASS1 > > > 7 BASS1 > > > > > > > > > > > > > > > I would Like to perform the following: > > > . read table 1 > > > . match table 1 against table 2, using App_ID column, and return > > > the following Profile_Num from table 2: > > > . 0909 - exact match > > > . 001AAA - close matches > > > . 000A223 - close match > > > . 01A345 - close match > > > > > > THANKS! > > > > > > (POSTED AGAIN FOR CORRECTION)
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dave |
last post by:
After following Microsofts admonition to reformat my system before doing a
final compilation of my app I got many warnings/errors upon compiling an rtf
file created in word. I used the Help...
|
by: Jacek Generowicz |
last post by:
Where can I find concise, clear documentation describing what one has
to do in order to enable Python's internal help to be able to provide
descriptions of Python keywords ?
I am in a situation...
|
by: wukexin |
last post by:
Help me, good men. I find mang books that introduce bit "mang header
files",they talk too bit,in fact it is my too fool, I don't learn it, I have
do a test program, but I have no correct doing...
|
by: Colin J. Williams |
last post by:
Python advertises some basic service:
C:\Python24>python
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
With...
|
by: Corepaul |
last post by:
Missing Help Files
When I enter "recordset" as the keyword and search the Visual Basic Help index,
I get many topics of interest in the resulting list. But there isn't any
information available...
|
by: Steve |
last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp
My expectation is that a developer using my DLL would be able to access this help file during his development time...
|
by: Mark |
last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my
home computer has an abbreviated help screen not 2% of the help on my laptop.
All the settings look the same on both...
|
by: JonathanOrlev |
last post by:
Hello everybody,
I wrote this comment in another message of mine, but decided to post it
again as a standalone message.
I think that Microsoft's Office 2003 help system is horrible, probably...
|
by: trunxnirvana007 |
last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
'UPGRADE_WARNING: Couldn't resolve...
|
by: hitencontractor |
last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003.
I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About.
The application...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |