0
Create procedure [dbo].[proc_Search_Username](@username varchar(25))
as 
  begin
    Declare @AccStatus int
    Set @AccStatus = 15

     while (@AccStatus = (select account_status from users where username like @username+'%'))
       begin
         select username from users where username like @username+'%'
       end
  end

In above Stored Procedure i want to get all users info.. whose username start with "a" at the same time i want to check they account is active or inactive if account is inactive i dont want to display they information... Only active user info.

1
  • 1
    Your approach simple makes no sense. Sample data and desired results would help clarify what you are trying to do. Commented May 7, 2016 at 15:57

1 Answer 1

1

Try something like this instead....

Create procedure [dbo].[proc_Search_Username](@username varchar(25))
as 
begin
    Declare @AccStatus int
    Set @AccStatus = 15;

         select username from users 
         where username like @username+'%'
         and account_status = @AccStatus
end

dont really see the reason why would you declare a variable for @AccStatus inside the procedure and then assign a value and then pass it to the query, simply pass the value to the query unless you are planning to pass this variable to the procedure. Then make it the procedure variables .

Sign up to request clarification or add additional context in comments.

1 Comment

@Sri have a look at this How to accept an answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.