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

varchar 型の代わりに nvarchar を使用します。

于 2012-10-21T15:24:44.970 に答える