How to pass SQL stored procedure NVARCHAR parameter with Hebrew?

IgorM

I'm trying to pass an NVARCHAR parameter to my store procedure. The stored procedure is supposed to find all suppliers that match the specified criteria. The only problem I have is that I am trying to pass criteria that contains Hebrew.

ALTER PROCEDURE [dbo].[FindSupplier] 
    -- Add the parameters for the stored procedure here
    @search_criteria nvarchar(100) = ''
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    DECLARE @hebrew as bit = 0

    IF @search_criteria LIKE '%[אבגדהוזחטיחכךילמנפףערקשת]%'
    BEGIN
        SET @hebrew = 1
    END

    IF @hebrew = 0 
    BEGIN

        SELECT comn020.t_suno 'Supplier Code'
        , hebcom020.t_nama 'Supplier Name1'
            , hebcom020.t_namb 'Supplier Name2'

        FROM com020 WITH (NOLOCK)

        INNER JOIN hebcom020 WITH (NOLOCK)
            ON hebcom020.t_suno = com020.t_suno

        WHERE (LTRIM(RTRIM(com020.t_suno)) LIKE N'%' + @search_criteria + '%')
           OR (SOUNDEX(LTRIM(RTRIM(com020.t_suno))) LIKE N'%' + SOUNDEX(@search_criteria) + '%')
           OR (LTRIM(RTRIM(hebcom020.t_nama)) LIKE N'%' + @search_criteria + '%')
           OR (SOUNDEX(LTRIM(RTRIM(hebcom020.t_nama))) LIKE N'%' + SOUNDEX(@search_criteria) + '%')
           OR (LTRIM(RTRIM(hebcom020.t_namb)) LIKE N'%' + @search_criteria + '%')
           OR (SOUNDEX(LTRIM(RTRIM(hebcom020.t_namb))) LIKE N'%' + SOUNDEX(@search_criteria) + '%')

    END

    ELSE  /* hebrew */
    BEGIN
        SELECT com020.t_suno 'Supplier Code'
             , hebcom020.t_nama 'Supplier Name1'
             , hebcom020.t_namb 'Supplier Name2'

        FROM com020 WITH (NOLOCK)

        INNER hebcom020 WITH (NOLOCK)
            ON hebcom020.t_suno = com020.t_suno

        WHERE hebcom020.t_nama Collate Hebrew_CI_AI LIKE N'%' + @search_criteria + '%' Collate Hebrew_CI_AI
            OR (LTRIM(RTRIM(hebcom020.t_namb)) LIKE N'%' + @search_criteria + '%')
    END

END

When I'm trying to pass something like exec FindSupplier 'ב' the SQL server recognizes char 'ב' as '?'

Your help will be highly appreciated

UPD: exec FindSupplier N'ב' worked

UPD2: In Visual Studio need to run sp with following string

="exec FindSupplier N'" & Parameters!search_criteria.Value & "'"
Solomon Rutzky

The problem is simply that the string literal used in the LIKE condition is not prefixed with an N to indicate that it is a Unicode string. The following example shows the difference:

DECLARE  @search_criteria NVARCHAR(100) = N'ב';

IF @search_criteria LIKE '%[אבגדהוזחטיחכךילמנפףערקשת]%'
BEGIN
    PRINT 'WithOUT "N"-prefix';
END;

IF @search_criteria LIKE N'%[אבגדהוזחטיחכךילמנפףערקשת]%'
BEGIN
    PRINT 'WITH "N"-prefix';
END;

Returns:

WITH "N"-prefix

To more easily understand why there is this difference in behavior, consider the following:

-- when the DB has a default collation of Latin1_General_100_CI_AS_SC (code page 1252)
SELECT  '%[אבגדהוזחטיחכךילמנפףערקשת]%'
-- %[????????????????????????]%

-- when the DB has a default collation of Hebrew_100_CI_AS_SC (code page 1255)
SELECT  '%[אבגדהוזחטיחכךילמנפףערקשת]%'
-- %[אבגדהוזחטיחכךילמנפףערקשת]%

The string literals are parsed in the code page used by the default collation of the current database. If the code page can support these characters, then not prefixing with the upper-case "N" will work. But, if those characters do not exist in that code page, then they are converted into "?"s.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to pass SQL stored procedure NVARCHAR parameter with Hebrew?

From Dev

NVARCHAR(MAX) - As SQL Stored Procedure Output Parameter

From Dev

How to pass two values to a single parameter in SQL Server stored procedure?

From Dev

How to pass schema as parameter to a stored procedure in sql server?

From Dev

How to pass output parameter to a Stored Procedure?

From Dev

how to get value of parameter and pass it to a stored procedure?

From Dev

How to pass output parameter to a Stored Procedure?

From Dev

SQL stored procedure: how to concatenate parameter value?

From Dev

How to Pass null value to stored procedure in sql

From Dev

How can I pass and process an array of varchars as parameters to/within a SQL Server stored procedure parameter?

From Dev

How to pass column name as well as Table Name to a stored procedure as a parameter in SQL Server?

From Dev

How to pass dynamically created filters as parameter of stored procedure in SQL Server and filter data?

From Dev

How to pass dynamically created filters as parameter of stored procedure in SQL Server and filter data?

From Dev

How can I pass and process an array of varchars as parameters to/within a SQL Server stored procedure parameter?

From Dev

pass a loop as parameter to a stored procedure

From Dev

t-sql stored procedure pass FIELD name as a parameter

From Dev

Delphi - pass table valued parameter to SQL Server stored procedure

From Dev

Delphi - pass table valued parameter to SQL Server stored procedure

From Dev

How to pass single quote text as parameter to stored procedure in sqlserver

From Dev

How to pass a temp table as a parameter into a separate stored procedure

From Dev

How to pass a parameter name into a stored procedure with an optional param in asp

From Dev

How to pass an out parameter in oracle stored procedure for python

From Dev

How to pass a parameter in stored procedure while dynamically adding columns in a table

From Dev

How to set stored procedure parameter for may or may not pass the values by user?

From Dev

SQL Server Stored Procedure Parameter

From Dev

sql server stored procedure IN parameter

From Dev

SQL Server Stored Procedure Parameter

From Dev

SQL Server: How to use a database name as a parameter in a stored procedure?

From Dev

SQL Server: How to use a database name as a parameter in a stored procedure?

Related Related

  1. 1

    How to pass SQL stored procedure NVARCHAR parameter with Hebrew?

  2. 2

    NVARCHAR(MAX) - As SQL Stored Procedure Output Parameter

  3. 3

    How to pass two values to a single parameter in SQL Server stored procedure?

  4. 4

    How to pass schema as parameter to a stored procedure in sql server?

  5. 5

    How to pass output parameter to a Stored Procedure?

  6. 6

    how to get value of parameter and pass it to a stored procedure?

  7. 7

    How to pass output parameter to a Stored Procedure?

  8. 8

    SQL stored procedure: how to concatenate parameter value?

  9. 9

    How to Pass null value to stored procedure in sql

  10. 10

    How can I pass and process an array of varchars as parameters to/within a SQL Server stored procedure parameter?

  11. 11

    How to pass column name as well as Table Name to a stored procedure as a parameter in SQL Server?

  12. 12

    How to pass dynamically created filters as parameter of stored procedure in SQL Server and filter data?

  13. 13

    How to pass dynamically created filters as parameter of stored procedure in SQL Server and filter data?

  14. 14

    How can I pass and process an array of varchars as parameters to/within a SQL Server stored procedure parameter?

  15. 15

    pass a loop as parameter to a stored procedure

  16. 16

    t-sql stored procedure pass FIELD name as a parameter

  17. 17

    Delphi - pass table valued parameter to SQL Server stored procedure

  18. 18

    Delphi - pass table valued parameter to SQL Server stored procedure

  19. 19

    How to pass single quote text as parameter to stored procedure in sqlserver

  20. 20

    How to pass a temp table as a parameter into a separate stored procedure

  21. 21

    How to pass a parameter name into a stored procedure with an optional param in asp

  22. 22

    How to pass an out parameter in oracle stored procedure for python

  23. 23

    How to pass a parameter in stored procedure while dynamically adding columns in a table

  24. 24

    How to set stored procedure parameter for may or may not pass the values by user?

  25. 25

    SQL Server Stored Procedure Parameter

  26. 26

    sql server stored procedure IN parameter

  27. 27

    SQL Server Stored Procedure Parameter

  28. 28

    SQL Server: How to use a database name as a parameter in a stored procedure?

  29. 29

    SQL Server: How to use a database name as a parameter in a stored procedure?

HotTag

Archive