为什么我得到“过程期望类型为'ntext / nchar / nvarchar'的参数'@statement'。”当我尝试使用sp_executesql时? [英] Why do I get "Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'." when I try to use sp_executesql?

查看:159
本文介绍了为什么我得到“过程期望类型为'ntext / nchar / nvarchar'的参数'@statement'。”当我尝试使用sp_executesql时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么会出现此错误


过程期望类型为'ntext / nchar / nvarchar'的参数'@statement'。

Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'.

当我尝试使用 sp_executesql 吗?

推荐答案

听起来像您用VARCHAR语句调用sp_executesql时,它需要是NVARCHAR。

Sounds like you're calling sp_executesql with a VARCHAR statement, when it needs to be NVARCHAR.

例如这将产生错误,因为@SQL需要为NVARCHAR

e.g. This will give the error because @SQL needs to be NVARCHAR

DECLARE @SQL VARCHAR(100)
SET @SQL = 'SELECT TOP 1 * FROM sys.tables'
EXECUTE sp_executesql @SQL

因此:

DECLARE @SQL NVARCHAR(100)
SET @SQL = 'SELECT TOP 1 * FROM sys.tables'
EXECUTE sp_executesql @SQL

这篇关于为什么我得到“过程期望类型为'ntext / nchar / nvarchar'的参数'@statement'。”当我尝试使用sp_executesql时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆