★☆★实在忍不住了,要向你们推荐一个网站★☆★

lynx1111 2004-04-29 03:07:54
http://www.mssqlcity.com/

仔细看,有很多东西。
...全文
4782 26 打赏 收藏 转发到动态 举报
写回复
用AI写文章
26 条回复
切换为时间正序
请发表友善的回复…
发表回复
shyyu 2004-04-30
  • 打赏
  • 举报
回复
GOOD
8992026 2004-04-29
  • 打赏
  • 举报
回复
我觉得转excel根本不应该在数据库里解决,而是在excel里解决。用sp_OACreate等给人难受的感觉。


8992026 2004-04-29
  • 打赏
  • 举报
回复
zjcxc(邹建):你的在哪里能找到?
internetcsdn 2004-04-29
  • 打赏
  • 举报
回复
my god
zjcxc 2004-04-29
  • 打赏
  • 举报
回复
导出Excel的那个值得讨论,它那种方法效率是较低的,至少比我的方法效率低很多.

不过它的方法有一个好处就是创建的是当前版本的Excel文件,这点比我的好.
General521 2004-04-29
  • 打赏
  • 举报
回复
lyns1111中的select是否可改成set?
hychieftain 2004-04-29
  • 打赏
  • 举报
回复
鸟E文,我要把你吃掉!!!!
shadow22 2004-04-29
  • 打赏
  • 举报
回复
E文的看着好辛苦啊.
bambooboy 2004-04-29
  • 打赏
  • 举报
回复
TO: lynx1111(任我行:一个PLMM看着就兴奋的男人)

开玩笑管开玩笑,这版权费还是要交的
lynx1111 2004-04-29
  • 打赏
  • 举报
回复
to : bambooboy(爱网络的人跑到了数据库版块,认了!)
开玩笑的!我这人就是喜欢开玩笑。

其实国内的sql server资料,论坛,我只发现csdn/sql server的东西全些,水平高些。
(可能是我不知道,哪位还知道有别的地方高分奉送)

虽然外国资料看着很吃力,但是代码看着就是舒服。
progress99 2004-04-29
  • 打赏
  • 举报
回复
還有導出成word,好東東
swich 2004-04-29
  • 打赏
  • 举报
回复
see
lvltt 2004-04-29
  • 打赏
  • 举报
回复
好帖 up
lynx1111 2004-04-29
  • 打赏
  • 举报
回复
wo kao !

搂主怎么不早通知我??

害我辛辛苦苦找了这长时间!!!!!!

这就是你不对了?

做人怎么能这样呢?
lynx1111 2004-04-29
  • 打赏
  • 举报
回复
/*
Version: SQL Server 7.0/2000
Created by: Alexander Chigrik
http://www.MSSQLCity.com/ - all about MS SQL
(SQL Server Articles, FAQ, Scripts, Tips and Test Exams).

This stored procedure can be used instead of sp_lock stored procedure
to return more detailed locking view (it can return user name, host name,
database name, object name, index name and object owner).
This is the example to use sp_lock2:

EXEC sp_lock2
*/

USE MASTER
GO
IF OBJECT_ID('sp_lock2') IS NOT NULL DROP PROC sp_lock2
GO
CREATE PROCEDURE sp_lock2
@spid1 int = NULL, /* server process id to check for locks */
@spid2 int = NULL /* other process id to check for locks */
as

set nocount on
/*
** Show the locks for both parameters.
*/
declare @objid int,
@indid int,
@dbid int,
@string Nvarchar(255)

CREATE TABLE #locktable
(
spid smallint
,loginname nvarchar(20)
,hostname nvarchar(30)
,dbid int
,dbname nvarchar(20)
,ObjOwner nvarchar(128)
,objId int
,ObjName nvarchar(128)
,IndId int
,IndName nvarchar(128)
,Type nvarchar(4)
,Resource nvarchar(16)
,Mode nvarchar(8)
,Status nvarchar(5)
)

if @spid1 is not NULL
begin
INSERT #locktable
(
spid
,loginname
,hostname
,dbid
,dbname
,ObjOwner
,objId
,ObjName
,IndId
,IndName
,Type
,Resource
,Mode
,Status
)
select convert (smallint, l.req_spid)
,coalesce(substring (s.loginame, 1, 20),'')
,coalesce(substring (s.hostname, 1, 30),'')
,l.rsc_dbid
,substring (db_name(l.rsc_dbid), 1, 20)
,''
,l.rsc_objid
,''
,l.rsc_indid
,''
,substring (v.name, 1, 4)
,substring (l.rsc_text, 1, 16)
,substring (u.name, 1, 8)
,substring (x.name, 1, 5)
from master.dbo.syslockinfo l,
master.dbo.spt_values v,
master.dbo.spt_values x,
master.dbo.spt_values u,
master.dbo.sysprocesses s
where l.rsc_type = v.number
and v.type = 'LR'
and l.req_status = x.number
and x.type = 'LS'
and l.req_mode + 1 = u.number
and u.type = 'L'
and req_spid in (@spid1, @spid2)
and req_spid = s.spid
end
/*
** No parameters, so show all the locks.
*/
else
begin
INSERT #locktable
(
spid
,loginname
,hostname
,dbid
,dbname
,ObjOwner
,objId
,ObjName
,IndId
,IndName
,Type
,Resource
,Mode
,Status
)
select convert (smallint, l.req_spid)
,coalesce(substring (s.loginame, 1, 20),'')
,coalesce(substring (s.hostname, 1, 30),'')
,l.rsc_dbid
,substring (db_name(l.rsc_dbid), 1, 20)
,''
,l.rsc_objid
,''
,l.rsc_indid
,''
,substring (v.name, 1, 4)
,substring (l.rsc_text, 1, 16)
,substring (u.name, 1, 8)
,substring (x.name, 1, 5)
from master.dbo.syslockinfo l,
master.dbo.spt_values v,
master.dbo.spt_values x,
master.dbo.spt_values u,
master.dbo.sysprocesses s
where l.rsc_type = v.number
and v.type = 'LR'
and l.req_status = x.number
and x.type = 'LS'
and l.req_mode + 1 = u.number
and u.type = 'L'
and req_spid = s.spid
order by spID
END
DECLARE lock_cursor CURSOR
FOR SELECT dbid, ObjId, IndId FROM #locktable
WHERE Type <>'DB' and Type <> 'FIL'

OPEN lock_cursor
FETCH NEXT FROM lock_cursor INTO @dbid, @ObjId, @IndId
WHILE @@FETCH_STATUS = 0
BEGIN

SELECT @string =
'USE ' + db_name(@dbid) + char(13)
+ 'update #locktable set ObjName = name, ObjOwner = USER_NAME(uid)'
+ ' from sysobjects where id = ' + convert(varchar(32),@objid)
+ ' and ObjId = ' + convert(varchar(32),@objid)
+ ' and dbid = ' + convert(varchar(32),@dbId)

EXECUTE (@string)

SELECT @string =
'USE ' + db_name(@dbid) + char(13)
+ 'update #locktable set IndName = i.name from sysindexes i '
+ ' where i.id = ' + convert(varchar(32),@objid)
+ ' and i.indid = ' + convert(varchar(32),@indid)
+ ' and ObjId = ' + convert(varchar(32),@objid)
+ ' and dbid = ' + convert(varchar(32),@dbId)
+ ' and #locktable.indid = ' + convert(varchar(32),@indid)

EXECUTE (@string)

FETCH NEXT FROM lock_cursor INTO @dbid, @ObjId, @IndId
END
CLOSE lock_cursor
DEALLOCATE lock_cursor

SELECT * FROM #locktable
return (0)
-- END sp_lock2
GO
csdnwhycn 2004-04-29
  • 打赏
  • 举报
回复
先谢了,收下慢慢消化
lynx1111 2004-04-29
  • 打赏
  • 举报
回复
/*
Version: SQL Server 7.0/2000
Created by: Alexander Chigrik
http://www.MSSQLCity.com/ - all about MS SQL
(SQL Server Articles, FAQ, Scripts, Tips and Test Exams).

This stored procedure can be used to export the text string into
Microsoft Word. You can pass the text string and the file name
(if the file name was not specified, the c:\ImportToWord.doc
will be used) into this stored procedure, as in the example below:

EXEC ExportToWord @Text = 'Test example',
@filename = 'c:\ImportToWord.doc'
*/

IF OBJECT_ID('ExportToWord') IS NOT NULL DROP PROC ExportToWord
GO

CREATE PROCEDURE ExportToWord (
@Text varchar(200) = null,
@filename varchar(200) = 'c:\ImportToWord.doc'
)
AS
DECLARE @object int,
@Range int,
@Documents int,
@Document int,
@hr int,
@result_str varchar(255)

IF @Text IS NULL
BEGIN
PRINT 'You should write text'
RETURN
END

SET NOCOUNT ON

EXEC @hr = sp_OACreate 'Word.Application', @object OUT
IF @hr <> 0
BEGIN
PRINT 'error create Word.Application'
RETURN
END

EXEC @hr = sp_OAGetProperty @object, 'Documents', @Documents OUT
IF @hr <> 0
BEGIN
PRINT 'error create Documents'
RETURN
END

EXEC @hr = sp_OAMethod @Documents, 'Add', @Document OUT
IF @hr <> 0
BEGIN
PRINT 'error with method Add'
RETURN
END

EXEC @hr = sp_OAGetProperty @Document, 'Range', @Range OUT
IF @hr <> 0
BEGIN
PRINT 'error create Range'
RETURN
END

EXEC @hr = sp_OASetProperty @Range, 'Text', @Text
IF @hr <> 0
BEGIN
PRINT 'error set Text'
RETURN
END

SELECT @result_str = 'SaveAs("' + @filename + '")'
EXEC @hr = sp_OAMethod @Document, @result_str
IF @hr <> 0
BEGIN
PRINT 'error with method SaveAs'
RETURN
END

EXEC @hr = sp_OAMethod @Documents, 'Close'
IF @hr <> 0
BEGIN
PRINT 'error with method Close'
RETURN
END

EXEC @hr = sp_OADestroy @object
IF @hr <> 0
BEGIN
PRINT 'error destroy Word.Application'
RETURN
END
GO
lynx1111 2004-04-29
  • 打赏
  • 举报
回复
/*
Version: SQL Server 7.0/2000
Created by: Alexander Chigrik
http://www.MSSQLCity.com/ - all about MS SQL
(SQL Server Articles, FAQ, Scripts, Tips and Test Exams).

This stored procedure can be used to insert the result set of the
particular select statement into Excel file (c:\ImportToExcel.xls,
by default).
You can pass the server name, user name, user password, the select
statement to execute, and the file name to store the results set,
as in the example below:

EXEC ExportToExcel @server = '.',
@uname = 'sa',
@QueryText = 'SELECT au_fname FROM pubs..authors',
@filename = 'c:\ImportToExcel.xls'
*/

IF OBJECT_ID('ExportToExcel') IS NOT NULL DROP PROC ExportToExcel
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
IF @hr <> 0
BEGIN
PRINT 'error Connect'
RETURN
END
END
ELSE
BEGIN
EXEC @hr = sp_OAMethod @SQLServer, 'Connect', null, @server, @uname, @pwd
IF @hr <> 0
BEGIN
PRINT 'error Connect'
RETURN
END
END

SELECT @result_str = 'ExecuteWithResults("' + @QueryText + '")'
EXEC @hr = sp_OAMethod @SQLServer, @result_str, @QueryResults OUT
IF @hr <> 0
BEGIN
PRINT 'error with method ExecuteWithResults'
RETURN
END

EXEC @hr = sp_OAMethod @QueryResults, 'CurrentResultSet', @CurrentResultSet OUT
IF @hr <> 0
BEGIN
PRINT 'error get CurrentResultSet'
RETURN
END

EXEC @hr = sp_OAMethod @QueryResults, 'Columns', @Columns OUT
IF @hr <> 0
BEGIN
PRINT 'error get Columns'
RETURN
END

EXEC @hr = sp_OAMethod @QueryResults, 'Rows', @Rows OUT
IF @hr <> 0
BEGIN
PRINT 'error get Rows'
RETURN
END

EXEC @hr = sp_OACreate 'Excel.Application', @object OUT
IF @hr <> 0
BEGIN
PRINT 'error create Excel.Application'
RETURN
END

EXEC @hr = sp_OAGetProperty @object, 'WorkBooks', @WorkBooks OUT
IF @hr <> 0
BEGIN
PRINT 'error create WorkBooks'
RETURN
END

EXEC @hr = sp_OAGetProperty @WorkBooks, 'Add', @WorkBook OUT
IF @hr <> 0
BEGIN
PRINT 'error with method Add'
RETURN
END

EXEC @hr = sp_OAGetProperty @object, 'Range("A1")', @Range OUT
IF @hr <> 0
BEGIN
PRINT 'error create Range'
RETURN
END

SELECT @indRow = 1
SELECT @off_Row = 0
SELECT @off_Column = 1

WHILE (@indRow <= @Rows)
BEGIN
SELECT @indColumn = 1

WHILE (@indColumn <= @Columns)
BEGIN

EXEC @hr = sp_OAMethod @QueryResults, 'GetColumnString', @result_str OUT, @indRow, @indColumn
IF @hr <> 0
BEGIN
PRINT 'error get GetColumnString'
RETURN
END

EXEC @hr = sp_OASetProperty @Range, 'Value', @result_str
IF @hr <> 0
BEGIN
PRINT 'error set Value'
RETURN
END

EXEC @hr = sp_OAGetProperty @Range, 'Offset', @Range OUT, @off_Row, @off_Column
IF @hr <> 0
BEGIN
PRINT 'error get Offset'
RETURN
END

SELECT @indColumn = @indColumn + 1

END

SELECT @indRow = @indRow + 1
SELECT @code_str = 'Range("A' + LTRIM(str(@indRow)) + '")'
EXEC @hr = sp_OAGetProperty @object, @code_str, @Range OUT
IF @hr <> 0
BEGIN
PRINT 'error create Range'
RETURN
END

END

SELECT @result_str = 'exec master..xp_cmdshell ''del ' + @filename + ''', no_output'
EXEC(@result_str)
SELECT @result_str = 'SaveAs("' + @filename + '")'
EXEC @hr = sp_OAMethod @WorkBook, @result_str
IF @hr <> 0
BEGIN
PRINT 'error with method SaveAs'
RETURN
END

EXEC @hr = sp_OAMethod @WorkBook, 'Close'
IF @hr <> 0
BEGIN
PRINT 'error with method Close'
RETURN
END

EXEC @hr = sp_OADestroy @object
IF @hr <> 0
BEGIN
PRINT 'error destroy Excel.Application'
RETURN
END

EXEC @hr = sp_OADestroy @SQLServer
IF @hr <> 0
BEGIN
PRINT 'error destroy SQLDMO.SQLServer'
RETURN
END
GO
lynx1111 2004-04-29
  • 打赏
  • 举报
回复
/*
Version: SQL Server 7.0/2000
Created by: Alexander Chigrik
http://www.MSSQLCity.com/ - all about MS SQL
(SQL Server Articles, FAQ, Scripts, Tips and Test Exams).

You can defragment all the indexes on all the tables in your database
periodically (for example, one time per week at Sunday) to reduce
fragmentation. The DBCC INDEXDEFRAG statement cannot automatically
defragment all indexes on all the tables in a database; it can only
work on one table and one index at a time. You can use the script
below to defragment all indexes in every table in the current database.
*/

DECLARE @TableName sysname
DECLARE @indid int
DECLARE cur_tblfetch CURSOR FOR
SELECT table_name FROM information_schema.tables WHERE table_type = 'base table'
OPEN cur_tblfetch
FETCH NEXT FROM cur_tblfetch INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
DECLARE cur_indfetch CURSOR FOR
SELECT indid FROM sysindexes WHERE id = OBJECT_ID (@TableName) and keycnt > 0
OPEN cur_indfetch
FETCH NEXT FROM cur_indfetch INTO @indid
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT 'Derfagmenting index_id = ' + convert(char(3), @indid) +
'of the ' + rtrim(@TableName) + ' table'
IF @indid <> 255 DBCC INDEXDEFRAG (0, @TableName, @indid)
FETCH NEXT FROM cur_indfetch INTO @indid
END
CLOSE cur_indfetch
DEALLOCATE cur_indfetch
FETCH NEXT FROM cur_tblfetch INTO @TableName
END
CLOSE cur_tblfetch
DEALLOCATE cur_tblfetch

outwindows 2004-04-29
  • 打赏
  • 举报
回复
up...
加载更多回复(6)

11,849

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 非技术版
社区管理员
  • 非技术版社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧