2009年7月24日星期五

drop table if exists in SQL Server

/* check if a table already exits before we drop it*/
IF EXISTS(SELECT name FROM sys.tables
WHERE name = 'Table_TempForTest')
BEGIN
/* drop table */
DROP TABLE Table_TempForTest
END
GO

/* see all the tables */
select * from sys.tables

powershell can't recognize the vairable setting for dtexec.exe

when I run dtexec.exe in powershell,the value after ";" is treated as a cmdlet and throw a exception" not recognized as a cmdlet, function, operable program, or script file".

This script can execute under cmd-line, but not in powershell.....

dtexec /f "C:\Users\Administrator\Documents\Visual Studio 2008\Projects\Integration Services Project1\Integration Services Project1\FileCopyPackage.dtsx" /set \package.variables[User::SourceFileName].Value;"C:\sharefolder\ssiscopied"

2009年7月21日星期二

在64位机上运行dtexec转换Excel数据

在64位操作系统上,dtexec默认是在64位模式下运行的,但是在三种情况下我们需要让dtexec运行于x86的模式:
  • 运行sql server 2000的DTS包
  • DTS包中使用的托管的.NET Framework Data Provider或者是本地OLE DB provider不支持64位模式
  • 脚本中引用的其它程序集或Com组件没有64位版本或者没有安装64位版本
如果我们用DTS来转换Excel数据,比如将数据导入sqlserver 2008 express,那么在读取Excel时就会使用OLE DB provider。OLE DB provider目前是没有64位版本的,按照前面说的这意味着在64模式我们无法使用DTS来导出Excel,而必须使用32位的模式。在dtexec的时候可以通过设置/x86参数来制定运行32位模式:

cd C:\Program Files\Microsoft SQL Server\100\DTS\Binn

dtexec /x86 /f c:\Sharefolder\Package2.dtsx /connection SourceConnectionExcel;"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Sharefolder\BusinessTemplate.xls;Extended Properties=Excel 8.0;HDR=YES" /connection DestinationConnectionOLEDB;"Data Source=.\SQLEXPRESS;Intial Catalog=SSISSampleDb;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=false"

pause
上面的例子中我们通过参数的形式重新设置了两个连接的值。在dtexec运行时,每个连接都可以通过一个单独的/connection参数来制定新的值,当有多个连接的时候,就设定多个/connection参数,这个好像在文档中没有提到。

参考资料:
64-bit Considerations for Integration Services

2009年7月10日星期五

sqlite 分页查询

select * from talbe_name limit @offset,@pageSize

一般 offset = pageSize * pageIndex