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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:51:41+00:00 2026-05-25T21:51:41+00:00

I am using CASE Statement in Stored procedure. I am using like create proc

  • 0

I am using CASE Statement in Stored procedure. I am using like

create proc USP_new
(
@searchtype varchar(30),
@stateName char(2),
    @keywords varchar(300),
    @locations varchar(100),
    @searchBy varchar(20),
    @keywordOption varchar(5),
    @jobType char(4),
    @startDate varchar(20),
    @endDate varchar(20),
    @companyID int

 ) 
 as begin
 declare @mainQuery varchar(8000)
SELECT @mainQuery = 'SELECT JobID, JobTitle, CompanyInfo, JobSummaryLong, ModifiedDate 
                 FROM Jobs 
                 WHERE IsActive = 1 '
    IF @startDate = '' BEGIN
        SELECT @mainQuery = @mainQuery + 'And ModifiedDate >= ''' + @startDate + ' 00:00:00'' '
    END
    SELECT @mainQuery = @mainQuery + 'And ModifiedDate <= ''' + @endDate + ' 23:59:59'''
SELECT
CASE  @mainQuery
WHEN 'state'    THEN 'ONE'
WHEN 'keyword' THEN 'Second'
WHEN 'company' THEN 'Third'
ELSE 'Other'

END

I want check more condition on this ‘Keyword’ like When Keyword and keyword is not null then
goto THEN condition..

I used like WHEN 'keyword' AND (@keyword IS NULL) THEN '' but its is giving syntax error.

IT is possible to check condition like this or any other way to check this

Thanks….

  • 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-25T21:51:42+00:00Added an answer on May 25, 2026 at 9:51 pm

    It’s really hard to tell what you are trying to accomplish with this stored proc, but I think you are definitely making thing harder than they need to be. You could probably re-write this as a single query like so:

    SELECT 
        KeywordResult = CASE 
            WHEN @keywords = 'state' THEN 'ONE'
            WHEN @keywords = 'keyword' THEN 'Second'
            WHEN @keywords = 'company' THEN 'Third'
            ELSE 'Other' END,
        JobID, 
        JobTitle, 
        CompanyInfo, 
        JobSummaryLong, 
        ModifiedDate 
     FROM 
        Jobs 
     WHERE 
        IsActive = 1
        AND (@StartDate <> '' AND ModifiedDate >= @StartDate)
        AND ModifiedDate <= @endDate + ' 23:59:59'''
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a stored procedure in MySQL, with a CASE statement. In the ELSE
I'm using a select statement inside a stored procedure. All I need to do
I read about using the CASE expression inside the WHERE clause here: http://scottelkin.com/sql/using-a-case-statement-in-a-sql-where-clause/ I'm
Besides readability is there any significant benifit to using a CASE WHEN statement vs
In a stored procedure (Oracle in my case), I want to add some values
I am executing a stored procedure via standard JDBC Connection using MS SQL Driver
Below is a simplified example of a stored procedure I've created. DELIMITER // CREATE
I need to create a stored procedure which takes 12 arguments and the query
I'm using LINQ to SQL to call a stored procedure. This stored procedure currently
PostgreSQL documentation recommends using a CallableStatement to call stored procedures. In the case of

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.