Home Forums SQL Server 2012 SQL Server 2012 - T-SQL Querying a Supersession Two Column Table with Multiple Supersessions in both Columns RE: Querying a Supersession Two Column Table with Multiple Supersessions in both Columns

  • Hi,

    Thanks for your hard work, it's appreciated. As it stands, executing that query results in:

    [Err] 42000 - [SQL Server] Must declare the scalar variable "@N"

    just after

    JOIN #Source b ON a.PartNo = b.PartNo

    The supersessions chain appears to have no logic to the old and new part number columns. Old and new numbers are mixed up in both. Unfortunately, I only have two columns worth of data, there is no time period logged for the part number change. Largely, because I suppose it's mostly irrelevant to the end user.

    The important thing, is that a list of previous part numbers is returned, regardless of order, for a point of reference.

    And yes, I will be pushing data from the UI in to the SELECT statement - purely the one part number that they are searching for though.

    For instance, if I searched for STC3333 in your example, it would redirect me to SFP500160 and then provide the UI with an array of previous part numbers linked to that latest number, as well as information from the [source] table for SFP500160.

    The more I think about it, the more of a nightmare I can see it becoming, with no point of reference on the supersession columns ...

    Can I send you the complete table, which I can export as either a CSV or TAB delimited file?

    Thanks.