Share via

SQL Server - using # in a string during a search

NachitoMax 416 Reputation points
2020-12-15T19:09:46.817+00:00

Hi

In our datatable, we have a ton of values that contain # because typically in construction, fasteners are graded with a # like this

'#8 x 2-1/2in

When i try to search for this in a Stored Procedure to filter the fastener size down, it fails because of the hash. I know its because the # has a meaning in a SQL statement so how would i get around it and find the rows using the hash in the search criteria?

Thanks

Nacho

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories


6 answers

Sort by: Most helpful
  1. EchoLiu-MSFT 14,626 Reputation points
    2020-12-16T07:48:25.277+00:00

    Hi @NachitoMax ,

    Welcome to TSQL Forum!Your question involves TSQL, so the engineer helped you add the TSQL tag.
    48663-image.png
    Maybe you are not familiar with Q&A forums. Generally speaking,when you post a question, please share us a minimal example that can illustrate the problem, and your table structure (CREATE TABLE …) and some sample data(INSERT INTO …)along with your expected result. So that we’ll get a right direction and make some test.Of course, you posted relevant information in the subsequent answers.

    I watched the full thread,thank you for posting the solution.It seems that null confuses you,the following instructions may be helpful to you:
    To determine whether an expression is NULL, use IS NULL or IS NOT NULL instead of comparison operators (such as = or !=).
    But when assigning values to variables, use comparison operators(such as = or !=).
    For more details,please refer to:IS NULL (Transact-SQL)

    If you have any question, please feel free to let me know.
    If the response is helpful, please click "Accept Answer" and upvote it.

    Regards
    Echo


    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    Hot issues November--What can I do if my transaction log is full?
    Hot issues November--How to convert Profiler trace into a SQL Server table

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.