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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:46:17+00:00 2026-06-18T01:46:17+00:00

I have problem in my program and I didn’t find error in my code.

  • 0

I have problem in my program and I didn’t find error in my code. I think it’s because StopProc. Can anybody check my stored procedure to see if it is valid?

ALTER PROCEDURE dbo.Update_FeatureUsers 
    (
        @FeatureID int,
        @UserID nvarchar (MAX),
        @CreatedUserID int
    )

AS
    SET NOCOUNT ON

    Declare @ParmDefinition nvarchar (400)
    Declare @Query nvarchar(MAX)

    SET @Query = N''
    SET @Query = @Query + N'DELETE FeatureUsers '
    SET @Query = @Query + N'FROM FeatureUsers '
    SET @Query = @Query + N'WHERE FeatureUsers.FeatureID = @FeatureID '
    SET @Query = @Query + N'    AND FeatureUsers.UserID NOT IN ('+ @UserID +')'

    EXECUTE sp_executesql @Query

    SET @Query = N''
    SET @Query = @Query + N'INSERT INTO FeatureUsers (FeatureID, UserID, CreatedUserID) '
    SET @Query = @Query + N'SELECT @FeatureID, Usager.UserID, @CreatedUserID '
    SET @Query = @Query + N'FROM Usager WITH (NOLOCK) '
    SET @Query = @Query + N'WHERE Usager.UserID IN ('+ @UserID +') '
    SET @Query = @Query + N'    AND Usager.UserID NOT IN '
    SET @Query = @Query + N'    ( '
    SET @Query = @Query + N'        SELECT FeatureUsers.UserID '
    SET @Query = @Query + N'        FROM FeatureUsers WITH (NOLOCK) '
    SET @Query = @Query + N'        WHERE FeatureUsers.UserID IN ('+ @UserID +') '
    SET @Query = @Query + N'            AND FeatureUsers.FeatureID = @FeatureID '
    SET @Query = @Query + N'    ) '

    SET @ParmDefinition = N'@FeatureID int '
    EXECUTE sp_executesql @Query, @ParmDefinition, @FeatureID = @FeatureID

    SET NOCOUNT OFF

    RETURN
  • 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-18T01:46:18+00:00Added an answer on June 18, 2026 at 1:46 am

    Your first dynamic SQL query also wants to access @FeatureID, but you’re not passing it.

    So move:

    SET @ParmDefinition = N'@FeatureID int '
    

    Up to the top of the proc and then call

    EXECUTE sp_executesql @Query,@ParmDefinition,@FeatureID = @FeatureID
    

    for both pieces of dynamic SQL.


    For the general strategy – it would be far better if you made the stored proc accept a table-valued parameter for @Users and then you wouldn’t need to use dynamic SQL at all.


    Actually, on second reading, your second query also references @CreatedUserID, so you’ll need to pass that across as a parameter to the second query. So you need to change the parameter definition between the two, or just add it to the parameters and pass it (pointlessly) to the first query.

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

Sidebar

Related Questions

This is my server code I have a problem because my program freeze and
I have a problem with 2D transformation program I have the source code import
I have some strange problem. I think I followed documentation correctly but my code
I'm having problems, while sending multiple attachments in my program. I didn't have any
Problem: Have made a small mail program which works perfectly on my developer pc
I have a problem with my iPhone program. I have imported a folder into
Basically i have a problem with this timer program I am trying to put
with my RCP program I have the problem that I want to have more
I have this problem when trying to run hello world program using android SDK.
i have a problem. Some sql in my program could be written by the

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.