-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwedo_sp_bcp_export.sql
More file actions
48 lines (33 loc) · 1019 Bytes
/
wedo_sp_bcp_export.sql
File metadata and controls
48 lines (33 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
USE [master]
GO
/****** Object: StoredProcedure [dbo].[sp_bcp_export] Script Date: 07/03/2014 18.25.17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE Proc [dbo].[wedo_sp_bcp_export]
@dbName varchar(30),
@tbName varchar(30),
@filePath varchar(80)
as
-- To allow advanced options to be changed.
-- EXEC sp_configure 'show advanced options', 1
-- GO
-- To update the currently configured value for advanced options.
-- RECONFIGURE
-- GO
-- To enable the feature.
-- EXEC sp_configure 'xp_cmdshell', 1
-- GO
-- To update the currently configured value for this feature.
-- RECONFIGURE
-- GO
-- Esempio di utilizzo: exec sp_bcp_export 'AM_SONNLEONARDO', 'IMPOSTAZIONI', 'c:\temp\Ordini.bcp'
declare @cmd varchar(200), @sname VARCHAR(500)
begin
SET @sname = cast(SERVERPROPERTY('ServerName') AS VARCHAR)
set @cmd = 'bcp.exe "select * from ' + @dbName + '..' + @tbName + '" queryout ' + @filePath + ' -N -S ' + @sname + ' -T -E'
print @cmd
exec xp_cmdShell @cmd
end
GO