开篇介绍

这是今天在帮别人看一个 2008R2 版本的项目时发现的一个 Bug,这个 Bug 在 SQL SERVER 2012 有的版本中可能已经解决,但在论坛上看到有的仍然存在。

在 SQL SERVER 2008 R2 版本中,比如从一个数据库表中取一个 BIGINT 类型的数据,赋值给一个 Int64 类型的变量,按照我们的理解肯定是正确的。

但是结果是报错了 -

错误原因:类型不一致造成的。

[Execute SQL Task] Error: An error occurred while assigning a value to variable "MAX_ID": "The type of the value being assigned to variable "User::MAX_ID" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.

".

当时也非常的奇怪,觉得这里的配置没有任何问题,怀疑同事机器环境有问题,于是就在我本机 SQL SERVER 2012 的环境下测试了一遍。

同样的逻辑是通过的。

后来到网上查了一下,果然是 SQL SERVER 2008 R2 版本中的一个 BUG,始自 2005,很惭愧,我到现在才发现这是一个 BUG。

http://blogs.msdn.com/b/mattm/archive/2007/04/18/why-can-t-i-store-my-bigint-result-in-an-int64-variable.aspx

Why can’t I store my BIGINT result in an Int64 variable?

The native providers (OLEDB, ODBC, ADO – ADO.NET doesn't have this problem) in the Execute SQL Task return the BIGINT type as a String, and not an Int64 as you'd expect. Attempting to store the result in an Int64 variable gives you an error along the lines of:

[Execute SQL Task] Error: An error occurred while assigning a value to variable "xxxx": "The type of the value being assigned to variable "xxxx" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object."

Although this behavior is documented in the books online entry, we don't explain why it was done this way. Being somewhat new to the SSIS development team, I had to do some digging to find out for myself. It turns out that at the time this was implemented, there wasn't cross platform support for the 8-byte integer type (VT_I8/VT_UI8) in VARIANTs -- specifically, on Windows 2000. Now that supporting Win2k is no longer an issue (for Katmai), we're free to change the behavior (while maintaining backwards compatibility for packages that are expecting the value as a string, of course).

Expect this as a likely change in an upcoming release.

https://connect.microsoft.com/SQLServer/feedback/details/260967/ssis-sql-server-bigint-doesnt-map-to-int64

如何解决

SQL SERVER 2012 版本已经纠正过来了,所以用 SQL SERVER 2012 的时候应该没有问题。如果还是使用 SQL SERVER 2008 R2 的话,解决的办法就是将数据类型改为 String,用它来接受 SQL SERVER 中 BIGINT 数据类型的数据。

另外,可能大家会问 - 如何这个变量正好也要写入一个 COLUMN类型为 BIGINT 类型的数据表中怎么办?

这个是没有任何问题的,如果 COLUMN 的类型是数值,日期的话,String 类型会自动发生转换插入的,因此 String 的变量会自动转换为对应的 BIGINT 插入到数据表中。

更多 BI 文章请参看 BI 系列随笔列表 (SSIS, SSRS, SSAS, MDX, SQL Server)  如果觉得这篇文章看了对您有帮助,请帮助推荐,以方便他人在 BIWORK 博客推荐栏中快速看到这些文章。

最新文章

  1. MySQL - 问题集 - "Waiting for table metadata lock"(待完善)
  2. Weibo SDK WP版本回调参数没有uid的解决方法
  3. 基于JAVA的全国天气预报接口调用示例
  4. 对《重建中国.NET生态系统》评论贴的总结
  5. window.self ->window.top->window.parent
  6. [技术分享] .NET下 , 上传图片的处理方式 , 贴上代码 .
  7. web前端基础篇②
  8. IOS缓存之NSCache缓存
  9. css清除浮动方法大全
  10. BZOJ 3275: Number( 最小割 )
  11. 《JAVASCRIPT高级程序设计》闭包
  12. hdu2444二分图最大匹配+判断二分图
  13. 201521123047 《Java程序设计》第4周学习总结
  14. 阿里电话面试问题----100万个URL如何找到出现频率最高的前100个?
  15. mysql数据库基本语句
  16. 利用random模块生成验证码
  17. LeetCode 33 搜索旋转排序数组
  18. Expo大作战(三十六)--expo sdk api之 ImagePicker,ImageManipulator,Camera
  19. Python3编写网络爬虫01-基本请求库urllib的使用
  20. [转]Nginx的负载均衡方式

热门文章

  1. Win7 64位系统 VS2010连接Oracle报错的问题
  2. SQL in与exists
  3. 在VMware上安装Ubuntu14.04 , Docker
  4. Ubuntu 10.04 32位桌面版+OpnERP 6.1.1
  5. Delphi 7学习开发控件
  6. cocos2d-x 坐标系
  7. 1032 - A-B 组合数学
  8. IOS 周几转化数字
  9. zz---Tomcat服务器下部署项目几种方式
  10. Eclipse: Launch failed. Binary not found