Wednesday, March 7, 2012

Execute SQL dynamically

Hi,
I want to execute some SQL statement that has more than 4000 characters, is
there any way to do it?
I'm using the exec sp_executesql command as following:
declare @.SQLString nvarchar(4000)
select @.SQLString = 'SQL statement more than 4000 characters'
exec sp_executesql @.SQLString
ThanksFerreira wrote:

> Hi,
> I want to execute some SQL statement that has more than 4000 characters, i
s
> there any way to do it?
> I'm using the exec sp_executesql command as following:
> declare @.SQLString nvarchar(4000)
> select @.SQLString = 'SQL statement more than 4000 characters'
> exec sp_executesql @.SQLString
> Thanks
declare @.var1 navarchar(4000)
declare @.var2 navarchar(4000)
set @.var1 = 'bla bla ..................'
set @.var2 = 'aaaabbbb ...............'
exec (@.var1 + @.var2)
Regards
Amish Shah|||http://www.sommarskog.se/dynamic_sql.html
Madhivanan
amish wrote:
> Ferreira wrote:
>
> declare @.var1 navarchar(4000)
> declare @.var2 navarchar(4000)
> set @.var1 = 'bla bla ..................'
> set @.var2 = 'aaaabbbb ...............'
> exec (@.var1 + @.var2)
> Regards
> Amish Shah|||Ferreira (Ferreira@.discussions.microsoft.com) writes:
> I want to execute some SQL statement that has more than 4000 characters,
> is there any way to do it? > I'm using the exec sp_executesql command as
> following:
> declare @.SQLString nvarchar(4000)
> select @.SQLString = 'SQL statement more than 4000 characters'
> exec sp_executesql @.SQLString
In addition to the other posts, note that if you are on SQL 2005, you can
use the new data type nvarchar(MAX) instead. This data type is unlimited
like ntext, but does not have all the restrictions of ntext.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

No comments:

Post a Comment