Whenever I try to use varchar
in sp_executesql
it's always throwing the following error:
Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'
Is there any reason we should use nvarchar
?
If "exec" allows us to use varchar, why not sp_executesql?
Sample Code:
DECLARE @IntVariable int;
DECLARE @SQLString **varchar**(500);--**we need to use nvarchar!! but why?**
DECLARE @ParmDefinition nvarchar(500);
SET @SQLString =
'SELECT nationalidnumber, NationalIDNumber, Title, LoginID
FROM AdventureWorks.HumanResources.Employee
WHERE nationalidnumber = @BusinessEntityID';
SET @ParmDefinition = '@BusinessEntityID int';
SET @IntVariable = 14417807;
EXECUTE sp_executesql @SQLString, @ParmDefinition,
@BusinessEntityID = @IntVariable;
SET @IntVariable = 109;
EXECUTE sp_executesql @SQLString, @ParmDefinition,
@BusinessEntityID = @IntVariable;