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 8460309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:34:17+00:00 2026-06-10T13:34:17+00:00

Can someone help please I dont know what I am doing wrong: IF EXISTS

  • 0

Can someone help please I dont know what I am doing wrong:

IF EXISTS ( SELECT  name
        FROM    sys.tables
        WHERE   name = N'MemberIdsToDelete' ) 
DROP TABLE [MemberIdsToDelete];
GO

SELECT  mm.memberid ,
        mm.aspnetuserid ,
        mm.email ,
        mm.RowNum AS RowNum
INTO    #MemberIdsToDelete
FROM    membership.members AS mm
        LEFT JOIN aspnet_membership AS asp ON mm.aspnetuserid = asp.userid
        LEFT JOIN trade.tradesmen AS tr ON tr.memberid = mm.memberid
WHERE   asp.isapproved = 0
        AND tr.ImportDPN IS NOT NULL
    AND tr.importDPN <> ''
ORDER BY mm.memberid

DECLARE @MaxRownum INT
SET @MaxRownum = ( SELECT   MAX(RowNum)
                   FROM     #MemberIdsToDelete
                 )

DECLARE @Iter INT
SET @Iter = ( SELECT    MIN(RowNum)
              FROM      #MemberIdsToDelete
            )

DECLARE @MemberId INT
DECLARE @TrademId INT
DECLARE @UId UNIQUEIDENTIFIER
DECLARE @Successful INT
DECLARE @OutputMessage VARCHAR(200)
DECLARE @Email VARCHAR(100)
DECLARE @Username VARCHAR(100)

SELECT  @MemberId = memberId ,
        @UId = AspNetUserId
FROM    MemberIdsToDelete
SELECT  @TrademId = TradesManId
FROM    trade.TradesMen
WHERE   memberId = @MemberId;

WHILE @Iter <= @MaxRownum 
  BEGIN
    SELECT  *
    FROM    #MemberIdsToDelete
    WHERE   RowNum = @Iter
  --more code here
    SET @Iter = @Iter + 1
  END

I just want to check if my table MemberIdsToDelete exists, if so drop it,
create MemberIdsToDelete with the results set from the select
loop through MemberIdsToDelete table and perform operations

I am getting error that RowNum does not exist

  • 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-06-10T13:34:18+00:00Added an answer on June 10, 2026 at 1:34 pm

    For a start, to check if a table exists and then drop accordingly, you need to use something like

    IF EXISTS (SELECT name 
               FROM sys.tables 
               WHERE name = N'MemberIdsToDelete') 
    DROP TABLE [MemberIdsToDelete];
    GO
    

    as for the error, your RowNum column does not exist when you are attempting to reference it. Include it in the SELECT statement

    select mm.memberid, mm.aspnetuserid, mm.email, mm.RowNum AS RowNum    
    into #MemberIdsToDelete     
    from membership.members as mm      
        left join aspnet_membership as asp       
            on mm.aspnetuserid=asp.userid       
                left join trade.tradesmen as tr       
                    on tr.memberid=mm.memberid       
    where asp.isapproved = 0 and tr.ImportDPN IS NOT NULL 
        and tr.importDPN <> '' 
    order by mm.memberid;
    GO  
    

    I hope this helps.

    Edit. Based on you additional error from your comment. You are now attempting to access a temporary table that does not exist. You must first populate the temporary table #MemberIdsToDelete before attempting to read from it. The invalid column error is down to the same problem. You are attempting to read a column called RowNum from the temporary table which does not exist.

    Edit2. Remove the ‘#’ from the #MemberIdsToDelete. You are inserting into a table not a temporary table. Or, Add a # to the select into above (see the code above). This will make it a temporary table as required.

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

Sidebar

Related Questions

I am getting date null and I dont know why, Can someone please help
Can someone please help to clarify? Also, please mention if there are other representation
can someone please help me out? I'm trying to create an input dynamically with
Can someone please help quickly mute or unmute the stage volume in Flash CS3
can someone please help me. why does this return an error: Dim stuff As
Can someone please help me with using Regex with NSPredicate? NSString *regex = @(?:[A-Za-z0-9]);
Can someone please help me out with a JavaScript/jQuery solution for this arithmetic problem:
Can someone please help me figure out a way to achieve the following (see
Can someone please help me to force my website to redirect to using www.
Please can someone help? I have the following code which uploads a file to

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.