problem with dynamic sql

  • Hi. My stored procedure is below:

    createPROCEDURE [dbo].[Insert_Dinamik]

    @baslik nvarchar(max)=null,

    @icerik nvarchar(max)=null,

    @dil varchar(10),

    @tablo varchar(50)

    AS

    BEGIN

    declare @sqlcum nvarchar(max)

    set @sqlcum ='insert into '+@tablo+' (baslik,icerik,dilid) values('''+@baslik+''','''+@icerik+''','''+@dil+''')'

    exec(@sqlcum)

    END

    this SP works good for saving data in latin languages. But if i use this SP languages like Russian,Arabic,datas are saved like ?????.

    How can i correct this .Thankss....

  • I suspect that your problem is happening because of some implicit type conversions.

    The string 'insert into ' is not unicode, nor is @tablo or @dil. When you concatenate every together, I think that there is an implicit type conversion of the 2 unicode columns. Try the following instead ....

    create PROCEDURE [dbo].[Insert_Dinamik]

    @baslik nvarchar(max)=null,

    @icerik nvarchar(max)=null,

    @dil Nvarchar(10),

    @tablo Nvarchar(50)

    AS

    BEGIN

    declare @sqlcum nvarchar(max)

    set @sqlcum =N'insert into '+@tablo+N' (baslik,icerik,dilid) values('''+@baslik+ N''','''+@icerik+ N''','''+@dil+ N''')'

    exec(@sqlcum)

    END

  • thanks. it worked.

  • happycat59 (5/18/2011)

    declare @sqlcum nvarchar(max)

    set @sqlcum =N'insert into '+@tablo+N' (baslik,icerik,dilid) values('''+@baslik+ N''','''+@icerik+ N''','''+@dil+ N''')'

    I'm sure this is a beginner question, but just the same...I see the letter N used every now and then (like your "=N'insert into" section above). What does N do?

    [font="Arial"]“Any fool can know. The point is to understand.”
    - Albert Einstein

    "DOH!"
    - Homer Simpson[/font]

  • Casts the string to nvarchar instead of default varchar

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

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