Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 714547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:05:15+00:00 2026-05-14T05:05:15+00:00

I am trying to establish upper / lower bound in my stored procedure below

  • 0

I am trying to establish upper / lower bound in my stored procedure
below and am having some problems at the end (I am getting no results
where, without the temp table inner join i get the expected results).
I need some help where I am trying to join the columns in my temp table #PageIndexForUsers
to the rest of my join statement and I am mucking something up with
this statement:

INNER JOIN 
#PageIndexForUsers ON  ( dbo.aspnet_Users.UserId =
#PageIndexForUsers.UserId     AND #PageIndexForUsers.IndexId >= @PageLowerBound AND
#PageIndexForUsers.IndexId <= @PageUpperBound )

I could use feedback at this point – and, any advice on how to improve
my procedure’s logic (if you see anything else that needs improvement) is also appreciated.

Thanks in advance…

ALTER PROCEDURE dbo.wb_Membership_GetAllUsers
    @ApplicationName       nvarchar(256),
    @sortOrderId           smallint = 0,
    @PageIndex             int,
    @PageSize              int
AS
BEGIN

    DECLARE @ApplicationId uniqueidentifier
    SELECT  @ApplicationId = NULL
    SELECT  @ApplicationId = ApplicationId FROM dbo.aspnet_Applications WHERE LOWER(@ApplicationName) = LoweredApplicationName

    IF (@ApplicationId IS NULL)
        RETURN 0

    -- Set the page bounds
    DECLARE @PageLowerBound int
    DECLARE @PageUpperBound int
    DECLARE @TotalRecords   int
    SET @PageLowerBound = @PageSize * @PageIndex
    SET @PageUpperBound = @PageSize - 1 + @PageLowerBound

BEGIN TRY

    -- Create a temp table TO store the select results
    CREATE TABLE #PageIndexForUsers
    (
        IndexId int IDENTITY (0, 1) NOT NULL,
        UserId uniqueidentifier
    )

    -- Insert into our temp table
    INSERT INTO #PageIndexForUsers (UserId)
    SELECT u.UserId
    FROM   dbo.aspnet_Membership m, dbo.aspnet_Users u
    WHERE  u.ApplicationId = @ApplicationId AND u.UserId = m.UserId
    ORDER BY u.UserName

    SELECT @TotalRecords = @@ROWCOUNT

    SELECT dbo.wb_Profiles.profileid, dbo.wb_ProfileData.firstname, dbo.wb_ProfileData.lastname, dbo.wb_Email.emailaddress, dbo.wb_Email.isconfirmed, dbo.wb_Email.emaildomain, dbo.wb_Address.streetname, dbo.wb_Address.cityorprovince, dbo.wb_Address.state, dbo.wb_Address.postalorzip, dbo.wb_Address.country, dbo.wb_ProfileAddress.addresstype,dbo.wb_ProfileData.birthday, dbo.wb_ProfileData.gender, dbo.wb_Session.sessionid, dbo.wb_Session.lastactivitydate, dbo.aspnet_Membership.userid, dbo.aspnet_Membership.password, dbo.aspnet_Membership.passwordquestion, dbo.aspnet_Membership.passwordanswer, dbo.aspnet_Membership.createdate
FROM dbo.wb_Profiles 
INNER JOIN dbo.wb_ProfileAddress
ON 
(
 dbo.wb_Profiles.profileid = dbo.wb_ProfileAddress.profileid
 AND dbo.wb_ProfileAddress.addresstype = 'home'
)
INNER JOIN dbo.wb_Address
ON dbo.wb_ProfileAddress.addressid = dbo.wb_Address.addressid
INNER JOIN dbo.wb_ProfileData 
ON dbo.wb_Profiles.profileid = dbo.wb_ProfileData.profileid 
INNER JOIN dbo.wb_Email 
ON 
(
 dbo.wb_Profiles.profileid = dbo.wb_Email.profileid 
 AND dbo.wb_Email.isprimary = 1
)
INNER JOIN dbo.wb_Session
ON dbo.wb_Profiles.profileid = dbo.wb_Session.profileid 
INNER JOIN
dbo.aspnet_Membership
ON dbo.wb_Profiles.userid = dbo.aspnet_Membership.userid
INNER JOIN
dbo.aspnet_Users
ON dbo.aspnet_Membership.UserId = dbo.aspnet_Users.UserId
INNER JOIN
dbo.aspnet_Applications 
ON dbo.aspnet_Users.ApplicationId = dbo.aspnet_Applications.ApplicationId
INNER JOIN 
#PageIndexForUsers ON  ( dbo.aspnet_Users.UserId =
#PageIndexForUsers.UserId     AND #PageIndexForUsers.IndexId >= @PageLowerBound AND
#PageIndexForUsers.IndexId <= @PageUpperBound )
ORDER BY CASE @sortOrderId
    WHEN 1 THEN dbo.wb_ProfileData.lastname
    WHEN 2 THEN dbo.wb_Profiles.username
    WHEN 3 THEN dbo.wb_Address.postalorzip
    WHEN 4 THEN dbo.wb_Address.state
END

END TRY
BEGIN CATCH

    IF @@TRANCOUNT > 0 ROLLBACK TRAN    
    EXEC wb_ErrorHandler
    RETURN 55555

END CATCH

   RETURN @TotalRecords

END
GO
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:05:15+00:00Added an answer on May 14, 2026 at 5:05 am

    You don’t have enough rows in #PageIndexForUsers, no?

    If @PageSize = 50 and you want @PageIndex 2, then you are looking for rows 100 to 149 from #PageIndexForUsers. Do you have this many rows?

    The row filter should be applied over the larger dataset that starts FROM dbo.wb_Profiles

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to establish a communication with an ONVIF camera, and I'm getting some
I'm trying to establish some way of mapping a String document to a HashMap
I am trying to establish a https connection but my URL contains some special
I am trying to establish a basic .NET Remoting communication between 2x 64bit windows
I am trying to establish the best practice for handling the creation of child
When trying to link some well established tools to my company's active directory, I
Trying to setup an SSH server on Windows Server 2003. What are some good
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
Just trying to establish whether prototype can do something like $$('#ID a:last').css('color','#111'); Any ideas
I'm trying to establish myself as an iPhone freelancer, and are currently negotiating with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.