Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

String Max Length Expand / Collapse
Author
Message
Posted Thursday, March 19, 2009 3:48 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, September 17, 2014 9:36 PM
Points: 30, Visits: 110
I want to delete all the stored procedure I created in the database. I write the following statements:
DECLARE @ssql varchar(8000)
SET @ssql = ''
SELECT @ssql = @ssql + 'Drop procedure ' + name + ' '
FROM sys.objects
WHERE type = 'p'
SELECT LEN(@ssql)
EXECUTE ( @ssql )

An error is appear
I found the max length of the @ssql is 4000.

Thanks
Post #679253
Posted Thursday, March 19, 2009 4:19 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 6:25 AM
Points: 1,682, Visits: 19,599
sys.objects.name is NVARCHAR


SELECT @ssql = @ssql + 'Drop procedure ' + CAST(name AS VARCHAR(128)) + ' '



____________________________________________________

How to get the best help on a forum

http://www.sqlservercentral.com/articles/Best+Practices/61537

Never approach a goat from the front, a horse from the rear, or a fool from any direction.
Post #679264
Posted Thursday, March 19, 2009 5:02 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, September 27, 2011 10:42 PM
Points: 309, Visits: 135

An error is appear
I found the max length of the @ssql is 4000.


Hi,
The issue is, eventhough you have set the @ssql variable as varchar(8000), it will take only 4000 characters. And the error you are getting is because of the dynamic query what you are constructing is having more than 4000 characters. Hence, I suggest you to use NVarchar(max) for @ssql variable. Hope this will solve the issue.
Regards,
Ashok S
Post #679277
Posted Thursday, March 19, 2009 8:33 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, September 17, 2014 9:36 PM
Points: 30, Visits: 110
Thank you man!
Post #680094
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse