Message
From
25/03/2010 17:15:15
 
General information
Fórum:
Microsoft SQL Server
Category:
Scripting
Miscellaneous
ID da thread:
01457214
ID da mensagem:
01457286
Views:
24
>>Add SET NOCOUNT ON at the begining of the script. Did you want to output the result of this select as a text? Did you see my blog - it solves very similar problem.
>>
>
>In other words, use BCP like this
>
>bcp "here goes your script'" queryout "c:\SP_scripts.sql" -S MyInstance -T -t -w
>
>>>>Biggest gotcha is making sure you have permissions enabled on the folder where you are writing the file.
>>>>
>>>>HTH
>>>
>>>Thank you Charles. There must be other gotchas I don't quite have my brain wrapped around. I end up with a result file that contains:
>>>
>>>
>>>(0 rows affected)
>>>
>>>
>>>the source script is
>>>
>>>
>>>WITH Procs (ProcName) AS 
>>>(
>>>    SELECT 
>>>        name 
>>>    FROM sys.procedures 
>>>    WHERE [type] = 'P' 
>>>		AND is_ms_shipped = 0 
>>>		AND [name] LIKE 'spMT%'
>>>)
>>>SELECT 
>>>'IF EXISTS(
>>>	SELECT *
>>>	FROM sys.objects
>>>	WHERE object_id = OBJECT_ID(N''[dbo].[' + ProcName + ']'') 
>>>		AND TYPE IN (N''P'', N''PC''))
>>>DROP PROCEDURE [dbo].[' + ProcName + ']
>>>GO
>>>
>>>'
>>>FROM Procs
>>>
>>>
>>>Which works perfectly when executed from SSMS.
>>>I suspect the problem is with the formatting of my script.

What I was hoping for was an easy way to set output to file in the script. This is a one time thing where I need to remove about 600 SPs from a DB (long story). My source script creates such a script that I can edit to preserve the 6 SPs in that DB that are still used. My generated script also checks for existance before the DROP...
Previous
Next
Responder
Mapa
View