SQL基础知识的一些总结

我写了下面一个SQL,其中的彩色部分是我之前不知道的技术,在这里总结一下:

 

select a.room_code, c.mach_gate,c.eng_name,item_name,b.result,
case
when b.result = '-----' then ''
when ISNUMERIC(b.result)=0 then ''
when b.downbound = null or b.downbound = '' then ''
when b.upbound = null or b.upbound = '' then ''
when convert(decimal(15,4),b.result) convert(decimal(15,4),b.downbound) then '↓'
when convert(decimal(15,4),b.result) > convert(decimal(15,4),b.upbound)   then '↑'
else '' end,
       b.downbound,'~',b.upbound,unit ,'*'+a.Reg_no+'*' as  Reg_no1
from as_report a,as_repentry b,as_code_item  c
where  a.rep_no = b.rep_no and
 a.room_code = c.room_code and
 a.mach_code = c.mach_code and
 b.item_code = c.item_code and
 isnull(a.Reg_no,'') =   1001 and a.rep_no in (  1002)
 order by a.rep_no,c.seq_no1

 

1、case  when then SQL里的条件语句格式。

2、ISNUMERIC(b.result)=0 当输入表达式的数为一个有效的整数、浮点数、money 或 decimal 类型,那么 ISNUMERIC 返回 1;否则返回 0。

3、decimal(a,b)
a指定指定小数点左边和右边可以存储的十进制数字的最大个数,最大精度38。
b指定小数点右边可以存储的十进制数字的最大个数。小数位数必须是从 0 到 a之间的值。默认小数位数是 0。

4、convert(a,b)

将b转换成a的数据类型。

5、isnull(a.Reg_no,'')

微软的 ISNULL() 函数用于规定如何处理 NULL 值。这里希望将NULL值转换成空字符串''

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值