2012-10-21 69 views
0

我通過使用N'...'知道我們可以在SQL Server中插入多語言數據。但我不知道如何使用它的參數。請幫我..如何使用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 [email protected]) 
    begin 
     Update t_LatestNews 
     set Titlle = [email protected], 
      DesCription = [email protected], 
      Image = [email protected], 
      dateOfnews = @DateOfNews, 
      modifiedDate = GETDATE(), 
      ModifiedBy = @ModifiedBy, 
      Isvisible = @IsVisible, 
      isdeleted = @IsDeleted 
     where 
      [email protected] 

     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 
+0

讓我粘貼我的代碼..那是行不通的............. – Ram

+0

更改您想要將多種語言保存爲nvarchar類型的字段。應該讓你這樣做。 – AMember

回答

1

修改你的存儲過程,看起來像這樣:

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 [email protected]) 
    begin 
     Update t_LatestNews set [email protected],[email protected],[email protected],[email protected],modifiedDate=GETDATE(),[email protected],[email protected],[email protected] where [email protected] 
     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 
+0

非常感謝......... .. – Ram

1

使用nvarchar的,而不是爲varchar類型。

+0

我已經將它們更改爲nvarchar,但仍然是相同的結果。 – Ram

+0

您試圖插入的值是什麼?我認爲你不需要現在使用的N前綴。 – AMember

+0

我想插入阿拉伯數值..和英文值 – Ram

0

最簡單的辦法是在表中插入數據作爲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 

enter image description here

相關問題