Solved

Need to execute A Large (>4000 char) unicode statement using sp_executesql

Posted on 2004-04-29
3
435 Views
Last Modified: 2008-01-09
I have a large statement @SQL that can dynamically grow up to about 6000 characters.

I need to execute this statement using :

sp_executesql

since the stored procedure parameter accepts only a single variable and the + operator is not allowed, how can I execute this statement using this stored procedure?
0
Comment
Question by:1markmc
  • 2
3 Comments
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 10952388
AFAIK, you will have to use a type of NTEXT.  You could create the query in two 4000-char NVARCHAR variables then concatenate that into an NTEXT field.  Sorry, don't know any other way.
0
 
LVL 1

Author Comment

by:1markmc
ID: 10952773
So how would I insert the ntext value (which as I understand it exists only as a table field) into the sp_executesql statement.

I worked up the following to test some ideas but haven't found any that work

declare @a nchar(3)
declare @b nchar(3)
set @a = N'sp_'
set @b = N'who'
declare @table table (sql ntext NULL)
insert into @table values (@a + @b)

--this doesn't work and so is where I need help
exec sp_executesql (select top 1 sql from @table)
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 250 total points
ID: 10952827
I think it can be an input parameter to a SP, but can then be manipulated as desired once inside the SP.  Sorry, I meant to mention that earlier.  If this is this being done within a SP, hopefully that will help.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question