|
GO
CREATE PROCEDURE ExportToExcel ( @server sysname = null, @uname sysname = null, @pwd sysname = null, @QueryText varchar(200) = null, @filename varchar(200) = 'c:\ImportToExcel.xls' ) AS DECLARE @SQLServer int, @QueryResults int, @CurrentResultSet int, @object int, @WorkBooks int, @WorkBook int, @Range int, @hr int, @Columns int, @Rows int, @indColumn int, @indRow int, @off_Column int, @off_Row int, @code_str varchar(100), @result_str varchar(255)
IF @QueryText IS NULL BEGIN PRINT 'Set the query string' RETURN END
-- Sets the server to the local server IF @server IS NULL SELECT @server = @@servername
-- Sets the username to the current user name IF @uname IS NULL SELECT @uname = SYSTEM_USER
SET NOCOUNT ON
EXEC @hr = sp_OACreate 'SQLDMO.SQLServer', @SQLServer OUT IF @hr <> 0 BEGIN PRINT 'error create SQLDMO.SQLServer' RETURN END
-- Connect to the SQL Server IF @pwd IS NULL BEGIN EXEC @hr = sp_OAMethod @SQLServer, 'Connect', null, @server, @uname
上一篇:如何判断是否以独占方式打开当前数据库?
下一篇:根据查询结果,生成XML文件
|