SolvedPrivate

SSIS package and using a Lookup tranformation

Posted on 2013-01-15
6
42 Views
Last Modified: 2016-02-10
I am currently working on a SSIS package and using a Lookup tranformation to output a value.
               
Lookup transformation uses a custom query as follows but the query returns mulitple results.

select * from (SELECT Account_Main_Financial_Id,
       Account_Main_Start_Code,
       Account_Main_End_Code,
       Account_Main_Financial_Level_Nbr
FROM   cdr.Account_Main_Financial
WHERE  Account_Main_Financial_Id > 0
       AND current_usage_ind = 1
       ) [refTable]
WHERE 4390 BETWEEN [refTable].[Account_Main_Start_Code] AND [refTable].[Account_Main_End_Code]
AND [refTable].Account_Main_Financial_Level_Nbr =
        ( SELECT MAX(Account_Main_Financial_Level_Nbr) FROM cdr.Account_Main_Financial
                WHERE [refTable].Account_Main_Financial_Id =Account_Main_Financial_Id )
               
Account_Main_Financial_Id        Account_Main_Start_Code        Account_Main_End_Code        Account_Main_Financial_Level_Nbr
1        0        4999        2
2        0        9999        1
20        4000        4499        3
47        4390        4399        4


I tried to use a parameter to resolve this issue but parameters in a sub query are not permitted in the custom query?

select * from (SELECT Account_Main_Financial_Id,
       Account_Main_Start_Code,
       Account_Main_End_Code,
       Account_Main_Financial_Level_Nbr
FROM   cdr.Account_Main_Financial
WHERE  Account_Main_Financial_Id > 0
       AND current_usage_ind = 1
       ) [refTable]
WHERE ? BETWEEN [refTable].[Account_Main_Start_Code] AND [refTable].[Account_Main_End_Code]
AND [refTable].Account_Main_Financial_Level_Nbr =
        ( SELECT MAX(Account_Main_Financial_Level_Nbr) FROM cdr.Account_Main_Financial
                WHERE ? BETWEEN [Account_Main_Start_Code] AND [Account_Main_End_Code] )
               

Esentially, I need to return the Max(Account_Main_Financial_Level_Nbr) so that only Account_Main_Financial_Id=47 is returned.

Unfortunately, its not 1=1 and there are multiple rows being returned. Is there an easier way to do this?

Many thanks in anticipation.
0
Comment
Question by:ExpertSkills
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 38781162
Something like this perhaps:
SELECT  a.Account_Main_Financial_Id,
        a.Account_Main_Start_Code,
        a.Account_Main_End_Code,
        d.Account_Main_Financial_Level_Nbr
FROM    cdr.Account_Main_Financial a
        INNER JOIN (SELECT  Account_Main_Financial_Id,
                            MAX(Account_Main_Financial_Level_Nbr) Account_Main_Financial_Level_Nbr
                    FROM    cdr.Account_Main_Financial
                    GROUP BY Account_Main_Financial_Id
                   ) d ON a.Account_Main_Financial_Id = d.Account_Main_Financial_Id
WHERE   a.Account_Main_Financial_Id > 0
        AND a.current_usage_ind = 1
        AND 4390 BETWEEN a.Account_Main_Start_Code AND a.Account_Main_End_Code

Open in new window

0
 

Author Comment

by:ExpertSkills
ID: 38781176
Thanks for your solution but when executing, still get multiple rows returned;

Account_Main_Financial_Id        Account_Main_Start_Code        Account_Main_End_Code        Account_Main_Financial_Level_Nbr
1        0        4999        2
2        0        9999        1
20        4000        4499        3
47        4390        4399        4
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 38781227
If all you want is a single row returned then do something like this:
;WITH MyCTE AS (
    SELECT  Account_Main_Financial_Id,
            Account_Main_Start_Code,
            Account_Main_End_Code,
            Account_Main_Financial_Level_Nbr,
            ROW_NUMBER() OVER (ORDER BY Account_Main_Financial_Level_Nbr DESC) Row
    FROM    cdr.Account_Main_Financial a
    WHERE   Account_Main_Financial_Id > 0
            AND current_usage_ind = 1
            AND 4390 BETWEEN Account_Main_Start_Code AND Account_Main_End_Code
             )
SELECT  Account_Main_Financial_Id,
        Account_Main_Start_Code,
        Account_Main_End_Code,
        Account_Main_Financial_Level_Nbr
FROM    MyCTE
WHERE   Row = 1

Open in new window

0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:ExpertSkills
ID: 38781258
That works a treat in Query Analyser but not in the SSIS Lookup Transformation; Advanced >  Modify the SQL Statement.

Any way to incorporate this into the Lookup transformation?
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 38781298
I am afraid I have no idea.
0
 

Author Closing Comment

by:ExpertSkills
ID: 38781326
Appreciate your help! Will try to get the code integrated into the component!
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question