| Author |
Topic |
|
nhess80
Yak Posting Veteran
83 Posts |
Posted - 2010-03-17 : 15:27:41
|
| Ok so I have given an example below of how the query works as of right now and I have also listed the results I’m trying to produce.Declare @LergData table(lata varchar(4),ocn varchar(4),npa varchar(3),nxx varchar(3),y varchar(2))insert into @LergData select 224,4804,201,204,0insert into @LergData select 224,8700,201,204,1insert into @LergData select 224,6664,201,204,2insert into @LergData select 224,325E,201,204,3insert into @LergData select 224,389C,201,204,4insert into @LergData select 224,389C,201,204,5insert into @LergData select 224,6664,201,204,6insert into @LergData select 224,6664,201,204,7insert into @LergData select 224,6623,201,204,8insert into @LergData select 224,4804,201,204,9insert into @LergData select 224,389C,201,204,'A'Declare @OCN Table (lata varchar(4),ocn varchar(4),inter decimal(18, 7),intra decimal(18, 7))insert into @OCN select 224,325E,0.0167,0.0167insert into @OCN select 224,389C,0.0165,0.0165insert into @OCN select 224,4804,0.0155,0.0155insert into @OCN select 224,6623,0.0145,0.0145insert into @OCN select 224,6664,0.0167,0.0167insert into @OCN select 224,8700,0.0165,0.0165SELECT b.npa +''+ b.nxx +''+ REPLACE(b.y,'A','') AS NPANXXY, a.inter,a.intraFROM @OCN AS a INNER JOIN @LergData AS b ON a.lata = b.lata AND a.ocn = b.ocnORDER BY NPANXXYCURRENT RESULTS201204 0.0165000 0.01650002012040 0.0155000 0.01550002012041 0.0165000 0.01650002012042 0.0167000 0.01670002012043 0.0167000 0.01670002012044 0.0165000 0.01650002012045 0.0165000 0.01650002012046 0.0167000 0.01670002012047 0.0167000 0.01670002012048 0.0145000 0.01450002012049 0.0155000 0.0155000DESIRED RESULTS201204 0.0165000 0.01650002012040 0.0165000 0.01650002012041 0.0165000 0.01650002012042 0.0165000 0.01650002012043 0.0165000 0.01650002012044 0.0165000 0.01650002012045 0.0165000 0.01650002012046 0.0165000 0.01650002012047 0.0165000 0.01650002012048 0.0165000 0.01650002012049 0.0165000 0.0165000Basically I want the 201204 Rate to supersede the other rates and just use the rate that goes with 201204. The "A" in the y column identifies this. This is just a small amount of data, the real data will contain others. For example:201210,2012101,2012102,2012103,2012104and whatever rate matches with 201210 will also be used with the others that match those first 6 digits.Please let me know if I did not explain this wellThanks for your help,Nick |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-03-17 : 17:02:50
|
I think this should work:SELECT b.npa +''+ b.nxx +''+ REPLACE(b.y,'A','') AS NPANXXY, dt.inter,dt.intraFROM @OCN AS a INNER JOIN @LergData AS b ON a.lata = b.lata AND a.ocn = b.ocncross join (select o.inter,o.intra from @LergData l join @OCN o on l.lata = o.lata AND l.ocn = o.ocn and l.y='A')dtORDER BY NPANXXY No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-03-18 : 04:01:50
|
I have made a correction, this should work:SELECT b.npa + b.nxx + REPLACE(b.y,'A','') AS NPANXXY, dt.inter,dt.intraFROM @OCN AS a INNER JOIN @LergData AS b ON a.lata = b.lata AND a.ocn = b.ocninner join (select l.npa + l.nxx as ttt, o.inter, o.intra from @LergData l join @OCN o on l.lata = o.lata AND l.ocn = o.ocn and l.y='A')dton dt.ttt = b.npa + b.nxxORDER BY NPANXXY No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
nhess80
Yak Posting Veteran
83 Posts |
Posted - 2010-03-18 : 12:53:08
|
Thank you very much, it worked perfectquote: Originally posted by webfred I have made a correction, this should work:SELECT b.npa + b.nxx + REPLACE(b.y,'A','') AS NPANXXY, dt.inter,dt.intraFROM @OCN AS a INNER JOIN @LergData AS b ON a.lata = b.lata AND a.ocn = b.ocninner join (select l.npa + l.nxx as ttt, o.inter, o.intra from @LergData l join @OCN o on l.lata = o.lata AND l.ocn = o.ocn and l.y='A')dton dt.ttt = b.npa + b.nxxORDER BY NPANXXY No, you're never too old to Yak'n'Roll if you're too young to die.
|
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-03-19 : 04:30:53
|
quote: Originally posted by nhess80 Thank you very much, it worked perfectquote: Originally posted by webfred I have made a correction, this should work:SELECT b.npa + b.nxx + REPLACE(b.y,'A','') AS NPANXXY, dt.inter,dt.intraFROM @OCN AS a INNER JOIN @LergData AS b ON a.lata = b.lata AND a.ocn = b.ocninner join (select l.npa + l.nxx as ttt, o.inter, o.intra from @LergData l join @OCN o on l.lata = o.lata AND l.ocn = o.ocn and l.y='A')dton dt.ttt = b.npa + b.nxxORDER BY NPANXXY No, you're never too old to Yak'n'Roll if you're too young to die.
welcome  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|