Question on providing parameter on the union query

  • Select * from (

    select
    EM.col1,
    ST.col2,
    ST.col3
    from vwEmployee EM
    inner join vwStudent ST
    on Em.ID = ST.ID

    Union

    select
    EH.col1,
    EH.col2,
    ST.col3
    from vwEmployeeHeader EH
    inner join vwStudent ST
    on Em.ID = ST.ID
    ) Results

    I have to give the paramter for this whole query ; How can i modify this query to add  EM.Date > ?

    I have the package where it checks the count of records form this query based on paramter date; where to add this EM.Date > ? on the abouve query?

    I know i can add on the first select query using where condition but i want this on the complete query

  • Considering that you are using a ? to define your parameter, can i assume that this in actually an SSIS SQL Execute task?

    If so, you could do:
    WITH Employee AS (
      select EM.col1,
             ST.col2,
             ST.col3,
            EM.date
      from vwEmployee EM
           inner join vwStudent ST on Em.ID = ST.ID

      Union

      select EH.col1,
            EH.col2,
            ST.col3,
            EH.Date
      from vwEmployeeHeader EH
           inner join vwStudent ST on Em.ID = ST.ID)

    SELECT E.col1, E.Col2, E.Col3
    FROM Employee E
    WHERE E.Date > ?;

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • I am getting parse error -

    Incorrect syntax near ')'.

    and also the columns SELECT E.col1, E.Col2, E.Col3
    FROM Employee E
    WHERE E.Date > ?;

    are showing invalid..

  • mcfarlandparkway - Monday, April 10, 2017 10:04 AM

    I am getting parse error -

    Incorrect syntax near ')'.

    and also the columns SELECT E.col1, E.Col2, E.Col3
    FROM Employee E
    WHERE E.Date > ?;

    are showing invalid..

    What is the full SQL you ran? I can't see any syntax errors in what I provided you.

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • Post the full T-SQL, please, including anything that may have run before it in the same window / task.

    Also, are you running this in a SSIS package, an SSMS window or in some other program?

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply