全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SQL及关系型数据库数据分析
1450 7
2015-04-22
以下SQL Server代码在你不能确定是否可以正常运行的话,建议您细读这篇文章,关于隐式数据转换。
  • DECLARE @A CHAR(3) = 'DEF';
  • SELECT CASE
  •   WHEN @A = 'DEF' THEN 0
  •   WHEN @A = 'GHI' THEN 1
  •   ELSE 'DOES NOT APPLY'
  • END;

  • GO
  • DECLARE @A CHAR(3) = 'ABC';
  • SELECT CASE
  •   WHEN @A = 'DEF' THEN 0
  •   WHEN @A = 'GHI' THEN 1
  •   ELSE 'DOES NOT APPLY'
  • END;

  • GO
  • DECLARE
  •   @A CHAR(3) = 'ABC',
  •   @B CHAR(5) = 'DEFGH',
  •   @C VARCHAR(10) = NULL,
  •   @D INT = 1234;
  • SELECT COALESCE(@C, @D, @A);

  • GO
  • DECLARE
  •   @A CHAR(3) = 'ABC',
  •   @B CHAR(5) = 'DEFGH',
  •   @C VARCHAR(10) = NULL,
  •   @D INT = 1234;
  • SELECT COALESCE(@C, @A, @D);

QQ截图20150422153945.png
How to Get SQL Server Data-Conversion Horribly Wrong
One of the most certain ways of going wrong with any relational database is to get data conversion wrong. Implicit data conversion is a good feature for the expert but  can cause a lot of trouble to the unwary. These boil down to seven ways of  failing to get data conversion right. Rob Sheldon explains and gives sage advice on how to avoid the problems。


Failure #1: Not understanding data type precedence
Failure #2: Not taking performance into consideration
Failure #3: Assuming all numbers are created equal
Failure #4: Relying on the ISNUMERIC built-in function
Failure #5: Underestimating the world of silent truncation
Failure #6: Not understanding date/time data
Failure #7: Importing Excel data without thought to data types
Failure #8: Treating XML just like any other string
Failure #9: Failing to take portability into account


信息来源:redgate





二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2015-4-22 19:10:00
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-4-22 19:15:34
谢谢分享~~~
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-4-23 14:25:05
学习学习.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-4-23 14:29:51
sunyiping 发表于 2015-4-23 14:25
学习学习.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-4-23 14:31:00
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群