4

我知道通过使用N'...'我们可以将多语言数据插入 SQL Server。但我不知道如何将它与参数一起使用。请帮我..

我的代码是:

Alter proc proc_T_NewsAddUpdate
(  
    @Id bigint,  
    @Title nvarchar(500),
    @Description nvarchar(1000),  
    @image nvarchar(200),  
    @DateOfNews datetime,  
    @CreatedBy bigint,  
    @ModifiedBy bigint,  
    @IsVisible int,  
    @IsDeleted int  
)  
as  
    if exists(select 1 from T_LatestNews where ID=@Id)  
    begin  
        Update t_LatestNews 
        set Titlle = N@Title, 
            DesCription = N@Description,
            Image = N@image,
            dateOfnews = @DateOfNews,
            modifiedDate = GETDATE(),
            ModifiedBy = @ModifiedBy,
            Isvisible = @IsVisible,
            isdeleted = @IsDeleted 
         where 
            ID=@Id  

        select 1  
    end  
    else  
    begin  
        insert into t_latestnews (Titlle, Description, Image, dateofnews, CreatedDate, ModifiedDate, CreatedBy, ModifiedBy, isvisible, isdeleted) 
        values(@Title, @Description, @image, @DateOfNews, GETDATE(), GETDATE(), @CreatedBy, @ModifiedBy, @IsVisible, @IsDeleted)  

        select 1  
    end
4

3 回答 3

4

最简单的解决方案是将数据作为 NVARCHAR 数据类型插入表中,如下所示。

--创建表

CREATE TABLE TBL_LANG

(

LNAME VARCHAR(50),

LTXT NVARCHAR(100)

)

– 插入不同语言的“Hello World”

INSERT INTO TBL_LANG

VALUES ('English',N'Hello World')

INSERT INTO TBL_LANG

VALUES ('Hindi',N'हैलो दुनिया')

INSERT INTO TBL_LANG

VALUES ('Chines',N'你好世界')

INSERT INTO TBL_LANG

VALUES ('Urdu',N'ہیلو دنیا')

--查看表数据

SELECT * FROM TBL_LANG

在此处输入图像描述

于 2016-06-02T10:34:32.293 回答
2

修改您的存储过程,如下所示:

Alter proc proc_T_NewsAddUpdate
(  
    @Id bigint,  
    @Title nvarchar(500),
    @Description nvarchar(1000),  
    @image nvarchar(200),  
    @DateOfNews datetime,  
    @CreatedBy bigint,  
    @ModifiedBy bigint,  
    @IsVisible int,  
    @IsDeleted int  
)  
as  
    if exists(select 1 from T_LatestNews where ID=@Id)  
    begin  
        Update t_LatestNews set Titlle=@Title,DesCription=@Description,Image=@image,dateOfnews=@DateOfNews,modifiedDate=GETDATE(),ModifiedBy=@ModifiedBy,Isvisible=@IsVisible,isdeleted=@IsDeleted where ID=@Id  
        select 1  
    end  
    else  
    begin  
        insert into t_latestnews (Titlle,Description,Image,dateofnews,CreatedDate,ModifiedDate,CreatedBy,ModifiedBy,isvisible,isdeleted) values(@Title,@Description,  
        @image,@DateOfNews,GETDATE(),GETDATE(),@CreatedBy,@ModifiedBy,@IsVisible,@IsDeleted)  
        select 1  
    end

然后像这样调用它:

exec proc_T_NewsAddUpdate
    @Id = 1, 
    @Title = N'Sample Title',
    @Description =  N'Sample Description',
    @image =  N'Sample Image',
    @DateOfNews = '1/1/2000',
    @CreatedBy = 1,
    @ModifiedBy = 1,
    @IsVisible = 1,
    @IsDeleted = 1
于 2012-10-21T15:53:39.153 回答
1

使用 nvarchar 代替 varchar 类型。

于 2012-10-21T15:24:44.970 回答