|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 乐yi忘忧 于 2012-6-27 19:37 编辑
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_ToExcel]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[p_ToExcel]
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE p_ToExcel
AS
DECLARE @sqlstring varchar(255)
DECLARE @dirstring varchar(255)
DECLARE @selectstring varchar(255)
DECLARE @str4 varchar(255)
SET @dirstring = 'C:\Report_D.xls'
SET @selectstring = '"SELECT * FROM test..Report_S"'
SET @str4 = ' -c -S"SYL-HP" -U"sa" -P"password"'''
SET @sqlstring = 'master..xp_cmdshell ''bcp ' +@selectstring+ ' queryout '+@dirstring+@str4
EXEC @sqlstring
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
这个存储过程执行总是出错,是字符串的拼接问题,请教该如何修改?
其实就是这么一句,想把保存路径通过savedialog写成动态的:
EXEC master..xp_cmdshell 'bcp "SELECT * FROM test..Report_S" queryout C:\Report_D.xls -c -S"SYL-HP" -U"sa" -P"password"'
|
|