• Hello ChrisM@home

    let me explain my question again.

    I want to do paging with Row_Number on several Join Table.

    My temp table fill by executing UserMidlist Procedure

    I use code below

    DECLARE @RowsPerPage INT = 10, @PageNumber INT = 6

    declare @UserMidListTable Table (Id Int,Mid int,ValueMid int,CatParent int, [Enabled] int,LastUpdate Datetime,Company nvarchar(max))

    insert into @UserMidListTable (Id ,Mid ,ValueMid ,CatParent ,[Enabled],LastUpdate ,Company)

    exec UserMidList '5C34A797-DCCB-40FF-B7AD-F6512803065E','20','0','0','10','1','2','','' -- add by kashani

    select * into #temp from @UserMidListTable

    select exhibitor.dbo.maintable.ID as maintableid,exhibitor.dbo.maintable.MID as maintableMid,exhibitor.dbo.maintable.OwnerID as maintableOwnerID,exhibitor.dbo.maintable.schemaID as maintableSchemaID,exhibitor.dbo.blgbelongs.Table1ID as blgTable1,exhibitor.dbo.blgbelongs.Table2ID as blgTable2

    from (select exhibitor.dbo.maintable.ID as maintableid,exhibitor.dbo.maintable.MID as maintableMid,exhibitor.dbo.maintable.OwnerID as maintableOwnerID,exhibitor.dbo.maintable.schemaID as maintableSchemaID,exhibitor.dbo.blgbelongs.Table1ID as blgTable1,exhibitor.dbo.blgbelongs.Table2ID as blgTable2

    ,ROW_NUMBER over (order by exhibitor.dbo.maintable.ID ) as ROW

    FROM #temp INNER JOIN exhibitor.dbo.maintable ON [#temp].[ValueMid]=exhibitor.dbo.maintable.ID inner join

    exhibitor.dbo.blgbelongs on exhibitor.dbo.blgbelongs.Table1ID= exhibitor.dbo.maintable.ID

    where exhibitor.dbo.blgbelongs.ID in (SELECT b2.id

    From exhibitor.dbo.Blgbelongs as b2

    where b2.blgid in (select id

    from exhibitor.dbo.blgid bi

    where bi.table1id=20 and bi.table2id=12))) as JOINTable

    JOINTable.ROW BETWEEN ((@PageNumber-1)*@RowsPerPage)+1

    AND @RowsPerPage*(@PageNumber)

    I have multiple identifier couldn't be bound in both my select statement.

    I should say I use alias name for my from clause and I solve my problem, is it ok?

    Thanks for your guide