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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:34:23+00:00 2026-05-14T07:34:23+00:00

Basically, we have an ASP website right now that I’m converting to PHP. We’re

  • 0

Basically, we have an ASP website right now that I’m converting to PHP. We’re still using the MSSQL server for the DB — it’s not moving.

In the ASP, now, there’s an include file with a giant sql query that’s being executed. This include sits on a lot of pages and this is a simple version of what happens. Pages A, B and C all use this include file to return a listing.

In ASP, Page A passes through variable A to the include file – page B passes through variable B — page C passes through variable C, and so on.

The include file builds the SQL query like this:

sql = "SELECT * from table_one LEFT OUTER JOIN table_two ON table_one.id = table_two.id"

then adds (remember, ASP), based on the variable passed through from the parent page,

Select Case sType
Case "A"
sql = sql & "WHERE LOWER(column_a) <> 'no' AND LTRIM(ISNULL(column_b),'') <> '' ORDER BY column_a
Case "B"
sql = sql & "WHERE LOWER(column_c) <> 'no' ORDER BY lastname, firstname
Case "C"
sql = sql & "WHERE LOWER(column_f) <> 'no' OR LOWER(column_g) <> 'no' ORDER BY column_g

As you notice, every string that’s added on as the second part of the sql query is different than the previous; not just one variable can be substituted out, which is what has me stumped.

How do I translate this case / switch into the stored procedure, based on the varchar input that I pass to the stored procedure via PHP?

This stored procedure will actually handle a query listing for about 20 pages, so it’s a hefty one and this is my first major complicated one. I’m getting there, though! I’m also just more used to MySQL, too. Not that they’re that different. 😛

Thank you very much for your help in advance.

Stephanie

  • 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-14T07:34:24+00:00Added an answer on May 14, 2026 at 7:34 am

    How do I translate this case / switch into the stored procedure, based on the varchar input that I pass to the stored procedure via PHP?

    In SQL Server, the CASE expression is not for control-of-flow like IF/ELSE.

    Use:

    DECLARE @SQL NVARCHAR(max)
        SET @SQL = N'SELECT ...'
    
        SET @SQL = @SQL + CASE sType
                            WHEN 'A' THEN ' WHERE ... '
                            WHEN 'B' THEN ' WHERE ... '
                            WHEN 'C' THEN ' WHERE ... '
                            ELSE ' '
                          END
    BEGIN
    
      EXEC sp_executesql @SQL
    
    END
    

    Lest we forget the ominous tale of Little Bobby Tables, best to read The curse and blessings of Dynamic SQL.

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

Sidebar

Related Questions

I have a asp.net-mvc website with a SQL server backend (using nhibernate for OR
We currently have an asp.net website that we use to generate html emails. Basically
Basically I have an asp.net website with login and search pages. Currently, I have
I basically need to login into another domain that is using asp.net membership. If
I have a project that will basically be a large brochure html website. Although
We have our own web server hosting our website that is open to the
I have a fairly big asp.net website that use GridView bound to the same
I have started converting my simple website to ASP.NET MVC, just to mess around
I have been using the embedded server that visual studio has to test my
I have an ASP website and I need to add a form that will

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.