Sql 是否使用变量更新存储过程中的非英语数据?

Sql 是否使用变量更新存储过程中的非英语数据?,sql,sql-server,stored-procedures,non-english,Sql,Sql Server,Stored Procedures,Non English,我有一个存储过程,它接受一个包含非英语数据的变量。我知道我们可以使用N这样做。但它不适用于变量。我怎样才能做到这一点 我想做这样的事情,但不起作用。下面是我的存储过程 Create Procedure tempUpdateCustomerSurvey ( @FeedbackText nvarchar(1000) ) As Begin Update tblCustomerSurvey Set GeneralFeedbackText = @FeedbackText

我有一个存储过程,它接受一个包含非英语数据的变量。我知道我们可以使用
N
这样做。但它不适用于变量。我怎样才能做到这一点

我想做这样的事情,但不起作用。下面是我的存储过程

Create Procedure tempUpdateCustomerSurvey
(
    @FeedbackText nvarchar(1000)
)
As
Begin
    Update  tblCustomerSurvey
    Set     GeneralFeedbackText = @FeedbackText
    Where   CustomerSurveyID = 1000 
End
public static Feedback InsertSurvey(int CustomerSurveyID, string GeneralFeedbackText)
   {
        try
        {
            int intDBReturnValue = Convert.ToInt32(SqlHelper.ExecuteScalar(SystemSettings.GetDBConnection(),
                                                                "tempUpdateCustomerSurvey",
                                                                CustomerSurveyID,
                                                                GeneralFeedbackText));

            Feedback f = new Feedback(FeedbackService.DB_OP_SPECIFICATION.INSERT, intDBReturnValue, "Customer survey");
            f.ProcessExceptionOrCustomErrorIfAvailable(-1, "System couldn't verify the survey information.");
            return f;
           }
           catch (Exception ex)
           {
                return new Feedback(FeedbackService.DB_OP_SPECIFICATION.INSERT, ex, "Customer survey");
           }
      }
它在表中存储“???????”

如果我使用下面的数据执行此SP,它将无法工作

Declare @GeneralFeedbackText Nvarchar(1000) = 'नमस्कार'
Exec tempUpdateCustomerSurvey @GeneralFeedbackText
知道存储过程接受来自C代码的数据。 下面是调用存储过程的核心C#方法

Create Procedure tempUpdateCustomerSurvey
(
    @FeedbackText nvarchar(1000)
)
As
Begin
    Update  tblCustomerSurvey
    Set     GeneralFeedbackText = @FeedbackText
    Where   CustomerSurveyID = 1000 
End
public static Feedback InsertSurvey(int CustomerSurveyID, string GeneralFeedbackText)
   {
        try
        {
            int intDBReturnValue = Convert.ToInt32(SqlHelper.ExecuteScalar(SystemSettings.GetDBConnection(),
                                                                "tempUpdateCustomerSurvey",
                                                                CustomerSurveyID,
                                                                GeneralFeedbackText));

            Feedback f = new Feedback(FeedbackService.DB_OP_SPECIFICATION.INSERT, intDBReturnValue, "Customer survey");
            f.ProcessExceptionOrCustomErrorIfAvailable(-1, "System couldn't verify the survey information.");
            return f;
           }
           catch (Exception ex)
           {
                return new Feedback(FeedbackService.DB_OP_SPECIFICATION.INSERT, ex, "Customer survey");
           }
      }
问题就在这里

Declare @FeedbackText nvarchar(1000) = 'नमस्कार'
您应该像这样使用
N
前缀

Declare @FeedbackText nvarchar(1000) = N'नमस्कार'
请参见下图以了解它们之间的区别


问题在于初始化变量值的方式-在第一个示例中,您没有使用字符串文本的
N
前缀,因此这会转换回非Unicode varchar字符串-这就是为什么您的表中会出现这些问号的原因。。。。按设计工作-从字符串文本初始化
nvarchar
变量时始终使用
N
前缀!如果您已经知道第二个代码段是有效的,那么您在这里要问什么“我如何才能实现它?”-使用可能与或重复的代码段,或者您可能需要显示调用代码。如果您传递的是字符串文字,它应该看起来像
EXEC tempUpdateCustomerSurvey N'Yorvalue'
-而不是
EXEC tempUpdateCustomerSurvey'Yorvalue'
@KomalR您刚刚删除了问题中最重要的部分。它现在没有意义了,应该关闭,因为
无法复制。张贴如何通过非英语文本的行。这就是问题所在,请仔细阅读我的问题。我知道在字符串前面加N是可行的,但我有一个动态SP,它接受C代码中的数据。所以你只需声明
@FeedbackText
参数的类型是Nvarchar(1000),它不起作用。@KomalR-你的问题没有提到任何关于“动态SP”(无论是什么)的内容,也不清楚你的问题是什么。如果要创建字符串文字,请使用
N
将其追加。如果您使用的是参数,请确保它是
nvarchar
。如果您的代码不起作用,请将其添加到您的问题中,这样我们就可以看到您做错了什么。@KomalR发布您的代码。变量是字符串,但如何传递该参数?您使用了字符串连接吗?那是一只虫子。您是否使用了参数化查询?您为参数指定了什么类型
NVarchar
Varchar
?如果使用字符串连接,是否使用了
N
前缀?