Querying a table repeatedly

  • Hi all,

    Im fairly new to this, I hope this hasnt been posted before!

    I have a table :

    From To   StatDate

    1       2

    2       3

    3       4

    4       5

    5       6

     

    Its used for merging, record one was merged to record 2, rec2 merged to rec 3 etc.

    What I need is to query the table passing in 6 as a parameter and gat the list above returned. I know how to write queries and pass parameters etc, its just the join syntax I cant figure out. Can anyone help me on this?

     

    Thanks,

    Helen

  • not enough info to really help yet helen.

    the real table definition is much more helpful, as well has the name /definition of the table you are "merging" it with, ie

    CREATE TABLE X (XINT INT,MOREINFO VARCHAR(30) )

    CREATE TABLE Y (XINT INT,MOREINFO VARCHAR(30) ,XINT INT REFERENCES X(XINT)

    it gives us everything we need to evaluate what you want.

    As far as a saved query with parameters, you are talking about a stored procedure.

    an example might be something like this:

    CREATE PROCEDURE PR_EXAMPLE(@DesiredID int)

    AS

    SELECT X.*,Y.* FROM X INNER JOIN Y ON x.XID = Y.YID AND X.XID = @DesiredID

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Hi Lowell,

     

    Problem solved - its a case of querying the table and writing results into a temporary table, then querying that table

     

    Thanks for the reply

Viewing 3 posts - 1 through 3 (of 3 total)

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