hi,
show u some example
/*
A. Execute a simple SELECT statement
This example creates and executes a simple SELECT statement that contains an embedded parameter named @level.
*/
use master
go
execute sp_executesql
N'select * from pubs.dbo.employee where job_lvl = @level',
N'@level tinyint',
@level = 35
N'select * from pubs.dbo.employee' , the N'abc123' will change the 'abc123' as nVarchar data string. variable-length (nvarchar) is Unicode data and use the UNICODE UCS-2 character set. normally we use it to support the 2 byte character, example like Thai character, or chinese character and other. nVarchar can support maximum 4000 character in a variable. other then using for chinese character , i aslo use it to contruct a dynamic select Statement, let user choose some question, contruct the Query Statement from the answer, and using the ExecuteSql to run the select Statement. u can refer the example above.
important note:]
Use nvarchar when the data entries in a column are expected to vary considerably in size.
SET ANSI_PADDING OFF does not apply to nchar or nvarchar. SET ANSI_PADDING is always ON for nchar and nvarchar.
regarding the sp_ExecuteSql, u may refer the SQL server book online.
regarding the nVarchar, u may refer the SQL server book online.