nvarchar parameters in stored procedure

  • Hello

    How Can I Add N Prefix To value of a parameter in stored procedure?

    Create Procedure Test

    @Param1 nvarchar(20)

    AS

    SET @Param1=N+@param1 -- this is wrong

  • You don't need to. If the parameter is defined as unicode, then there is no need to add the N before it.

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • thanks for your post 'Adi Cohn-120898' but see this:

    DECLARE @Col nvarchar(50)

    SET @Col='?'

    SELECT @Col

    DECLARE @Col2 nvarchar(50)

    SET @Col2=N'?'

    SELECT @Col2

    First Select result is '?' and second result is '?'

  • Eskandari (9/12/2011)


    thanks for your post 'Adi Cohn-120898' but see this:

    DECLARE @Col nvarchar(50)

    SET @Col='?'

    SELECT @Col

    DECLARE @Col2 nvarchar(50)

    SET @Col2=N'?'

    SELECT @Col2

    First Select result is '?' and second result is '?'

    This is beause you are using a constant to get the value into the varible. Check out my example:

    DECLARE @Col1 nvarchar(50)

    DECLARE @Col2 nvarchar(50)

    --First I get a value into @Col1. Because

    --I'm using an arabic letter, I need to

    --use unicode. Notice that I use it in the

    --part that works with the hard coded constant

    --and I don't need to use it as a prefix to the variable

    SET @Col1=N'?'

    SELECT @Col1

    --This is because of the original question.

    --Now I have the correct value in @Col1 and I

    --want to insert it into @Col2. Since @Col1 is defined

    --as unicode, I don't need to use the prefix N

    SET @Col2 = @Col1

    SELECT @Col1

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply