Search
Home
Articles
Backup
Books
Certification
FAQ
Products
Replication
Scripts
Seminars
Training
TSQL

MSDN Fourms
Philippine SSUG
Fort Worth SSUG
Oklahoma City SSDG

Resume

MHS Enterprises
BlowFrog Software
FilAm Software
AcrylicAcetate.com
Bargain Humidors
Western Humidor

Find Foreign Keys 1 2 3 4 5

The same holds true for the next calculation.           fkcolid = r.fkey1 * (1 - abs(sign(p.Value - 1))) + r.fkey2 * (1 - abs(sign(p.Value - 2))) + r.fkey3 * (1 - abs(sign(p.Value - 3))) +
    r.fkey4 * (1 - abs(sign(p.Value - 4))) + r.fkey5 * (1 - abs(sign(p.Value - 5))) + r.fkey6 * (1 - abs(sign(p.Value - 6))) + r.fkey7 * (1 - abs(sign(p.Value - 7))) +
    r.fkey8 * (1 - abs(sign(p.Value - 8))) + r.fkey9 * (1 - abs(sign(p.Value - 9))) + r.fkey10 * (1 - abs(sign(p.Value - 10))) + r.fkey11 * (1 - abs(sign(p.Value - 11))) +
    r.fkey12 * (1 - abs(sign(p.Value - 12))) + r.fkey13 * (1 - abs(sign(p.Value - 13))) + r.fkey14 * (1 - abs(sign(p.Value - 14))) + r.fkey15 * (1 - abs(sign(p.Value - 15))) +
    r.fkey16 * (1 - abs(sign(p.Value - 16))),
will produce a set of 16 rows that look like the following:

fkey1

fkey2

fkey3

fkey4

fkey5

fkey6

fkey7

fkey8

fkey9

fkey10

fkey11

fkey12

fkey13

fkey14

fkey15

fkey16

The final calculation     key_seq = 1 * (1 - abs(sign(p.Value - 1))) + 2 * (1 - abs(sign(p.Value - 2))) + 3 * (1 - abs(sign(p.Value - 3))) + 4 * (1 - abs(sign(p.Value - 4))) +
    5 * (1 - abs(sign(p.Value - 5))) + 6 * (1 - abs(sign(p.Value - 6))) + 7 * (1 - abs(sign(p.Value - 7))) + 8 * (1 - abs(sign(p.Value - 8))) + 9 * (1 - abs(sign(p.Value - 9))) +
    10 * (1 - abs(sign(p.Value - 10))) + 11 * (1 - abs(sign(p.Value - 11))) + 12 * (1 - abs(sign(p.Value - 12))) + 13 * (1 - abs(sign(p.Value - 13))) +
    14 * (1 - abs(sign(p.Value - 14))) + 15 * (1 - abs(sign(p.Value - 15))) + 16 * (1 - abs(sign(p.Value - 16))),
will produce the following:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

It should be noted here that I could apply the calculations directly, because the data in the fkey1...fkey16 and rkey1...rkey16 was numeric in origin (smallint).  If the data happened to be character in origin, then some additional processing would have been required.

Find Foreign Keys 1 2 3 4 5

Michael R. Hotek

All content on this site, except where noted, represents an original work of Michael R. Hotek and is protected by applicable copyright laws. The SQL Server FAQ is the sole work of Neil Pike. No page, portion of a page, or download may be used for commercial purposes in whole or in part without the express, written permission of the applicable author.