SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 adding the concordance to a collumn
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

goligol
Posting Yak Master

120 Posts

Posted - 07/18/2012 :  12:16:03  Show Profile  Reply with Quote
In the following code:
SELECT a.[BLS_io] iFMB

,imiters_io = case
when a.[BLS_io] = b.[fmb_io] then b.[miters_io]
end
,a.[iCom] cFMB

,cmiters_io = case
when a.[iCom] = b.[fmb_io] then b.[miters_io]
end
,a.[FoV]

FROM [BLS].[IO2012].[ACxC_1993] a
,[BLS].[IO2012].[io_concord_new] b

I am trying to add the concordance from the b table to the a table in a imiters_io and cmiters_io. b table is a 450 column which has all the items in a.icom and a.BLS_io.

But this code is adding more rows to the a table which is not wanted.

I am aware that in the b table for one fmb_io there are couple of miters_io:

fmb_io miters_io
1 5
1 6
1 7
2 3
2 4

But for me is enought to only take one of the miters_io(any) and not add more rows to a matrix.

Regards

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 07/18/2012 :  12:21:57  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
You don't have a join condition here so will get a cartesian product

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47023 Posts

Posted - 07/18/2012 :  12:27:12  Show Profile  Reply with Quote

SELECT *
FROM
(
SELECT ROW_NUMBER() OVER (PARTITION BY a.[BLS_io],a.[iCom]  ORDER BY (SELECT 1)) AS rn,
,a.[BLS_io] iFMB

,imiters_io = b1.[miters_io]
,a.[iCom] cFMB

,cmiters_io = b2.[miters_io]
,a.[FoV]

FROM [BLS].[IO2012].[ACxC_1993] a
left join [BLS].[IO2012].[io_concord_new] b1
on a.[BLS_io] = b1.[fmb_io] 
left join ,[BLS].[IO2012].[io_concord_new] b2
on a.[iCom] = b2.[fmb_io]
WHERE b1.[fmb_io] is not null
or  b2.[fmb_io] is not null
)t
WHERE Rn=1


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

goligol
Posting Yak Master

120 Posts

Posted - 07/18/2012 :  12:49:56  Show Profile  Reply with Quote
hello,
it is not working in my case, I was thinking if I have a one by one concordance in b(following) table I can figure out the rest:

SELECT [fmb_io]
,[miters_io]
FROM [BLS].[IO2012].[io_concord_new]
order by fmb_io


fmb_io miters_io
1 111335
1 1111A0
1 111400
1 1119A0
1 111910
2 112100
2 112100
2 112300
2 112A00
3 113A00
4 113300
5 114100
5 114200
6 115000
7 211000
8 212100
9 212210
9 2122A0


this to be computed as:

fmb_io miters_io
1 111335
2 112100
3 113A00
4 113300
5 114100
6 115000
7 211000
8 212100
9 212210
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000