Insert Nvarchar value in stored procedure

  • Hello,

    I have an stored procedure for inserting values

    create Procedure proc_Details_Insert

    (

    @Location nvarchar(4000),

    )

    as

    Begin

    INSERT INTO [Details] ([Location]) VALUES @Location)

    End

    It gives me error If I add prefix N for Unicode string

    INSERT INTO [Details] ([Location]) VALUES N@Location)

    How to resolve this? My column Location takes unicode values

    Regards

    Asif

  • Try

    INSERT INTO [Details] ([Location]) VALUES N''@Location

    or

    INSERT INTO [Details] ([Location]) VALUES N'@Location

    one of the above should resolve ur problem

    -Lk

  • Nothing needs resolving. The parameter is defined as an nvarchar, hence it is an nvarchar and will be inserted into the table as an nvarchar. The N prefix is only needed for literal strings. Because you have a typed parameter, SQL knows what the data type is.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • luckysql.kinda (9/7/2010)


    Try

    INSERT INTO [Details] ([Location]) VALUES N''@Location

    or

    INSERT INTO [Details] ([Location]) VALUES N'@Location

    Neither will work, as you would know if you'd done a syntax check before posting.

    INSERT INTO [Details] ([Location]) VALUES N''@Location

    Msg 102, Level 15, State 1, Line 1

    Incorrect syntax near ''.

    INSERT INTO [Details] ([Location]) VALUES N'@Location

    Msg 105, Level 15, State 1, Line 1

    Unclosed quotation mark after the character string '@Location

    '.

    Msg 102, Level 15, State 1, Line 1

    Incorrect syntax near '@Location

    '.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

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

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