Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Dance Doll
Yak Posting Veteran
54 Posts |
Posted - 2007-02-06 : 11:08:35
|
| Hi there,I try to run a query by using exec sp_executesql @sql command.The @sql is nvarchar(4000). The query string is too big that the exceed the maximum size of 4000 bytes. And the query is using temp table too. I can't use ntext type because of the #tmp table.Someone helps me?Thanks! |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-02-06 : 11:29:53
|
| Use N'String'instead of @sql? (I believe that the Statement for sp_ExecuteSQL can be ntext, thus presumably can be longer than 4000 characters if provided as a text stringKristen |
 |
|
|
Dance Doll
Yak Posting Veteran
54 Posts |
Posted - 2007-02-06 : 11:37:49
|
| Great!Thanks for all helps! |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-02-06 : 11:39:23
|
Well I haven't tried it, so I can't guarantee it will work but hopefully it will ... |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-02-06 : 21:04:31
|
Thought it is ntext internally, don't think there is much you can do. If your query is more than 4000 chars then, you might want to try to rewrite it or make use of temp table as a temporary storage of the query result for further processing.from BOLquote: sp_executesqlExecutes a Transact-SQL statement or batch that can be reused many times, or that has been built dynamically. The Transact-SQL statement or batch can contain embedded parameters.Syntaxsp_executesql [@stmt =] stmt[ {, [@params =] N'@parameter_name data_type [,...n]' } {, [@param1 =] 'value1' [,...n] }]Arguments[@stmt =] stmtIs a Unicode string containing a Transact-SQL statement or batch. stmt must be either a Unicode constant or a variable that can be implicitly converted to ntext. More complex Unicode expressions (such as concatenating two strings with the + operator) are not allowed. Character constants are not allowed. If a constant is specified, it must be prefixed with an N. For example, the Unicode constant N'sp_who' is legal, but the character constant 'sp_who' is not. The size of the string is limited only by available database server memory.stmt can contain parameters having the same form as a variable name, for example:N'SELECT * FROM Employees WHERE EmployeeID = @IDParameter'Each parameter included in stmt must have a corresponding entry in both the @params parameter definition list and the parameter values list.
KH |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-02-07 : 02:37:44
|
| Well, I had read that and figured that a N'Long text string' could be implicitly converted to ntext!So I've now tried it with an N'Constant' of about 20,000 characters and it seems to work ...Kristen |
 |
|
|
|
|
|
|
|