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

  • Home
  • SEARCH
  • 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 820409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:28:07+00:00 2026-05-15T02:28:07+00:00

please help me with writing this search sql stored procedure procedure may have different

  • 0

please help me with writing this search sql stored procedure
procedure may have different number of parameters at different time
so could any body help me with writing this query. I don’t know how to concatenate parameters.
i am new to stored procedure

CREATE PROCEDURE searchStudent
-- Add the parameters for the stored procedure here
@course int=null,
@branch int=null,
@admissionYear varchar(max)=null,
@passingYear varchar(max)=null,
@userName varchar(max)=null,
@sex varchar(max)=null,
@studyGap varchar(max)=null,
@firstName varchar(max)=null,
@lastName varchar(max)=null
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE query STR DEFAULT null

IF @course IS NOT NULL
THEN query=
SELECT * FROM [tbl_students] WHERE 

END
GO

please complete the query so that it can have parameters which are having values and can search from database on the basis of parameters value. But parameter may vary every time depends on search criteria.

  • 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-15T02:28:08+00:00Added an answer on May 15, 2026 at 2:28 am

    You would probably need to use Dynamic SQL to achieve this. First of all I would highly recommend reading this excellent article. http://www.sommarskog.se/dynamic_sql.html

    You’re dynamic sql would be something like this;

       Declare @query varchar(max)
    
       Set @query = 'Select * From dbo.MyTable Where '
    
       If @Course Is Not Null
       Begin
        Set @query = @query + 'Course = ' + Convert(varchar(10), @Course)
       end
    
       If @Branch Is Not Null
       Begin
        Set @query = @query + ' and Branch = ' + Convert(varchar(10), @Branch )
       end
    

    This is only an example! You will need to build in some checks to ensure that you have one (and only one) Where clause, you must ensure that the integer values are converted to string values correctly. You must also check that the parameters don’t have any special characters that could break the dynamic sql – like an apostrophe (')

    Using dynamic SQL can be painful and very difficult to get right.

    Good luck!

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

Sidebar

Related Questions

Hi can someone please help me in writing this regex. I need to search
Could you please help me with this one: In one of my scripts I
Please help me with this one, I've been writing a console applicaiton using the
Could you please help me with the following I writing an app using CoreData
can someone please help me out writing this code in objective C : function
Please help me somebody to convert unicodestring into string This is how i am
Please help me with this update query. I COMPLETELY understand how redundant this is
please help me arrange these 3 buttons horizontally like this photoshopped image: Please take
Please help me to figure this out. I am having two tab bar items
Please help me understand the following code snippet :- def any(l): whether any number

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.