EXCEL 导入SQL SERVER存储过程
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER proc [dbo].[pr_xls_to_tb]
@path varchar(200),--EXCEL路径名
@tbName varchar(30),--表名
@stName varchar(30) --excel中要读的SHEET名
as
declare @sql varchar(500),--最后要执行的SQL
@stName_Real varchar(35),--真正的SHEET名
@drop_sql varchar(300) -- 如果表已存在,先删除
set @stName_Real = '[' + @stName + '$]'
--set @path = 'C:\Inetpub\wwwroot\CarStock_ExcelWeb\Upload\CarStock\国贸汽车库存表20090630.xls'
--set @tbName = 't32'
--set @stName = '[不良资产$]'
set @sql =
'SELECT *
into '+ @tbName +'
from OpenDataSource(' + char(39)+ 'Microsoft.Jet.OLEDB.4.0' + char(39)+', '
+ char(39) +'Data Source=' + @path +';User ID=Admin;Password=;Extended properties=Excel 5.0;' + char(39)+')...'+@stName_Real
set @drop_sql = '
if exists(select * from sysobjects where name = ' + char(39) +@tbName + char(39)+')
begin
drop table '+@tbName+'
end '
--print @drop_sql
exec (@drop_sql)--先删除表
exec (@sql)--再创建表
/*
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
*/
调用:
exec pr_xls_to_tb 'C:\Tools\预算数据\ys_200908.xls' ,'ys_200908_new' ,'Source'
相关文档:
oracle tips
Exist的用法:
select gw.ndocid from
(select ndocid from wf_doc_gw_shouwen union select ndocid from wf_doc_gw_fawen) gw
where
not exists (select null from wf_doc_gw_sn sn where sn.ndocid=gw.ndocid)
2。把GW表和SN表里相同的NDOCID显示出来
select gw.ndocid from
(se ......
1. My test: (create and grant the sysdba to a new user by SQL*Plus)
CREATE USER FJTEST1 IDENTIFIED BY JEANJEANFANG;
GRANT SYSDBA TO FJTEST;
REVOKE SYSDBA from FJTEST;
CONNECT FJTEST1/JEANJEANFANG AS SYSDBA;
2. Using ORAPWD in windows:
C:\» ORAPWD;
(show help information)
3. to see th ......
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace DAL
{
......
1. SET DEADLOCK_PRIORITY
说明:控制在发生死锁情况时会话的反应方式。如果两个进程都锁定数据,并且直到其它进程释放自己的锁时,每个进程才能释放自己的锁,即发生死锁情况。
语法:SET DEADLOCK_PRIORITY { LOW | NORMAL | @deadlock_var }
参数:LOW   ......