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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:21:21+00:00 2026-05-12T11:21:21+00:00

My procedure was working fine in a 2005 database, but my PC died and

  • 0

My procedure was working fine in a 2005 database, but my PC died and when I set it up again I installed 2008 rather than 2005 – now this procedure doesn’t return any results. I ask the question about the difference between the 2 versions simply because I have used this logic before and I haven’t changed the procedure since I created it and it was working, the only change has been the fact I am now using SQL 2008

I wrote the procedure in Visual Studio and have noticed that when I paste the select statement into the SQL pane for the table that it is restructured and expanded so that each variation that could be expressed by combining the ANDs and ORs.

What I need is to be able to call this procedure optionally passing either parameter; so if I pass only the componentType it should evaluate the final statement part of the statement and use the value passed – if no value was passed then it would match the IS NULL side of the condition.

ALTER PROCEDURE dbo.uspSel_ComponentByType(
  @filterText       VARCHAR(50) = NULL 
, @componentType    CHAR(2)     = NULL) 
AS 
SELECT  [pkComponentID], [ComponentType], [ComponentName], [fkSupplierID], [Cost], [WastageCost]
FROM    [tblComponents] AS c INNER JOIN
        [tblSuppliers] AS s ON [c].[fkSupplierID] = [s].[pkSupplierID]
WHERE   ([ComponentName] LIKE @filterText + '%' OR [SupplierName] LIKE @filterText + '%')
 AND    [c].[IsDeleted] = 0
 AND    (@componentType IS NULL OR [ComponentType] = @componentType)
  • 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-12T11:21:21+00:00Added an answer on May 12, 2026 at 11:21 am

    I’m no SQL pro, but if I understand your intentions right, you should be able to use the sproc with no/either/both parameters and get expected results if you default @filterText to '' instead of NULL.

    ALTER PROCEDURE dbo.uspSel_ComponentByType(
        @filterText           VARCHAR(50)     = ''      ,
        @componentType        CHAR(2)         = NULL
    ) 
    AS 
        SELECT  ... --the rest of the sproc is unchanged
    

    As David M clarified, this is probably because SQL Server 2005 and 2008 handles string concatenation with NULL values differently. It seems that in SQL Server 2005

    'A string' + NULL = 'A string';
    

    while in SQL Server 2008

    'A string' + NULL = NULL;
    

    By changing the default to '', we made the default comparison '' + '%', which will always be treated as % and match everything, instead of NULL + '%', which will end upp NULL and match nothing.

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

Sidebar

Related Questions

I have a stored procedure that has been working just fine, but I recently
Is the following stored procedure code robust for multi-user application. It is working fine.
In SQL SERVER 2005 This query works fine : Select * from sys.procedures where
My Android app has two Spinners (dropdown menus) working fine. However, now I've added
I've written a stored procedure. It's working fine except taking the table name as
Actually i have created following procedure,which is working fine. CREATE or REPLACE PROCEDURE GET_NOS(
I am calling a stored procedure as a NamedQuery and it's working fine. The
Code that was working fine last week is suddenly throwing this exception: System.Data.SqlClient.SqlException (0x80131904):
I am working on a stored procedure with several optional parameters. Some of these
I'm working on a stored procedure in SQL Server 2000 with a temp table

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.