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'
Ïà¹ØÎĵµ£º
Differring Constraints:
Constraints can have the following attributes: DEFFERRABLE / NOT DEFFERRABLE, INITIALLY DEFFERRED / INITIALLY IMMEDIATE.
e.g.:
alter table dept2 add constraint dept2_id_pk primary key (department_id) deferrable initially deferred; // deferring constraint on creation. ......
CREATE VIEW MYVIEW
AS
SELECT * from bjxxdiweb_database2007.dbo.bm_tongji
UNION ALL
SELECT * from aa.DBO.chen
select * into aa..chen from bjxxdiweb_database2007.dbo.bm_tongji where 1=2
˵Ã÷£ºÊý¾Ý¿âAµÄ±íµÄ×Ö¶ÎÃû±ØÐëºÍÊý¾Ý¿âBµÄ±íµÄ×Ö¶ÎÃûÏàͬ£¬°üÀ¨Êý¾ÝÀàÐ͵ȡ£ ......
(×¢:outerµÄÒâ˼¾ÍÊÇ"ûÓйØÁªÉϵÄÐÐ"¡£)
1.cross join È«ÍâÁ¬½Ó(µÑ¿¨¶û³Ë»ý)
SELECT A.*, B.* from A FULL OUTER JOIN B ON A.ID = B.ID
2.inner join ÄÚÁ¬½Ó(Ôڵѿ¨¶û³Ë»ýµÄ½á¹û¼¯ÖÐÈ¥µô²»·ûºÏÁ¬½ÓÌõ¼þµÄÐÐ)
SELECT A.* from A INNER JOIN B ON A.ID=B.ID
3.left outer join ×óÍâÁ¬½Ó(ÔÚinner joinµÄ½á¹ ......
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
{
......