<address id="xpjh9"><listing id="xpjh9"><meter id="xpjh9"></meter></listing></address>

<address id="xpjh9"><address id="xpjh9"><listing id="xpjh9"></listing></address></address>
<noframes id="xpjh9">
<noframes id="xpjh9">

<address id="xpjh9"><address id="xpjh9"><listing id="xpjh9"></listing></address></address>
    <form id="xpjh9"></form><address id="xpjh9"><listing id="xpjh9"><menuitem id="xpjh9"></menuitem></listing></address>

      <noframes id="xpjh9">
      VB.net 2010 視頻教程 VB.net 2010 視頻教程 VB.net 2010 視頻教程
      SQL Server 2008 視頻教程 c#入門經典教程 Visual Basic從門到精通視頻教程
      當前位置:
      首頁 > 數據庫 > T-SQL >
      • sql語句大全之T-SQL 簡易小數處理

      • 2019-05-02 10:20 來源:未知

      今天因應同事提的一則需求,寫了一段 CASE WHEN 的整數與小數處理

      過程中居然踩了個雷,特此記錄下來

      首先,需求如下:

      當內容為整數或零時則去掉尾端的小數否則就顯示原本的小數內容

      若內容為 NULL 也維持不變

      例如: 120.000 要顯示為 120 , 而 120.12345 則維持不變 

      在聽完需求後,我快速寫了以下這段 CASE WHEN 判斷

      image

      但看起來行不通阿!!! 可以看到我在 THEN 的時候直接轉成INT類型,但出來的結果還是DECIMAL類型
      此時同事說了句,是不是有可能型態在CASE WHEN時就已經決定了

      經過測試大致整理出邏輯如下

      CASE WHEN 是透過所有 THEN 值的型態優先順序,來決定最終型態為何

      當其中一個型態無法做隱含轉換時(比如像下圖的文字無法直接轉換成小數) ,就會出錯

      image

       

      而透過下列的語法,可以自行測試各種組合的最終型態的優先權為何

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      DECLARE @T DECIMAL(10,4) = 192.1233
      SELECT
      SQL_VARIANT_PROPERTY(IntAndDecimal,'BaseType'),
      IntAndDecimal
      FROM
      (
      SELECT
      CASE
      WHEN @T = FLOOR(@T)
      THEN CAST(@T as varchar)
      WHEN @T > FLOOR(@T)
      THEN CAST(@T as INT)
      WHEN @T < FLOOR(@T)
      THEN CAST(@T as decimal)
      END as IntAndDecimal
      ) X  

       從下圖可以看到當CASE WHEN 同時有 varchar 、 int 、 decimal 、 float 時

      最後會統一轉換成float型態 

       

      相關的文件可以參考官網
      https://docs.microsoft.com/en-us/sql/t-sql/data-types/data-type-precedence-transact-sql?view=sql-server-2017

      最後

      以下就是我寫的完整語法,可以看到透過在 THEN 我分邊加了兩個 CAST 轉換

      在優先權的比較後,最後的型態會統一轉換成  Float ,所以原本會以 DECIMAL 為主的型態已經消失了


      相關的效果也可以參考兩個 Column  的值 ,最右邊為預期的結果,左邊則為原始結果

      image

      相關教程
      江苏快3 8988d.com | 7788332.com | www.86333.com | 66p88.cc | www.hjin6.com | www.7435o.com | www.202374.com | www.hg8875.com | 58955.com | www.xj7007.com | 4647dh.com | www.2109u.com | www.agg033.com | www.96386u.com | www.5049z.com | yz01.cc | www.xj1990.com | 1665bb.com | www.210613.com | www.68277888.com | 3405fff.com | www.5522k.cc | www.33302a6.com | 1294y.com | www.0088hgbb.com | 97799y.com | www.00840j.com | www.995t.net | 66000.com | www.www45641.com | www.ven4444.com | t365r.com | www.63606l.com | 3844bb.com | www.210155.com | www.5446hh.com | 2jsxxx.com | www.588767.com | www.5966rrr.com | 33111122.com | www.924377.com | www.383188.com | 496ii.com | www.9356l.com | www.hg773999.com | 3136dd.com | www.78700l.com | www.946386.com | 89777l.com | www.196606.com | 3936n.com | 50028866.com | www.9989572.com | www.333222b.com | 1213ggg.com | www.6011888.com | www.728055.com | 2566h4.com | www.pj56ii.com | www.yl0399.com | ii76669.com | www.78995.com | www.33166.com | 14683355.com | www.730631.com | www.20199pp.com | byc888c.com | www.579020.com | www.98698l.com | 6150s.com | www.177564.com | www.9895e.com | www.zz538.com | 1859002.com | www.88266s.com | www.3339193.com | x777dl.com | www.927320.com | www.88166u.com | 97297b.com | 8892958.com | www.78700d.com | www.552772.com | 8037hhh.com | www.404499.com | www.65045.com | www.u30226.com | 5856ccc.com | www.630155.com | www.06820z.com | www.pjshanghai.com | 4116w.com | www.kc53.com | www.00772e.com | vip66656.com | 3245u.com | www.846662.com | www.55mgm777.com | www.58777h.com | j4389.com | www.90305a.com | www.5856856.com | www.yh00bet.com | 3685j.com | 22rr8332.com | www.39500s.com | www.140suncity.com | 2355n.com | tt888y.com | www.960777a.com | www.6687m.com | www.2846j.com | 3662b.com | 55tt8332.com | www.00ttz.com | www.89599u.com | www.tushan98.com | 2214bb.com | 365225c.com | www.64059.com | www.71071e.com | www.223456r.com | 7003n.com | 9649v.com | www.9478q.com | www.89599w.com | www.8882558.com | 3522f.vip | 2546c.com | www.cly5.com | www.99552ww.com | www.hg0454.com | 70118b.com | 55797.com | www.307996.com | www.607116.com | www.baifucp.com | www.v2808.com | 9958988.com | x9996.com | www.106265.com | www.68689c.com | www.55545q.com | www.76543r.com | 7788332.com | m83377.com | www.177474.com | www.50026s.com | www.7225l.com | www.501333.com | www.6033n.com | f1915f.com | 20182013.com | www.90848a.com | www.3478j.cc | www.0601f.com | www.9737ii.com | www.32666r.com | 3169b.com | 53358h.com | 4995u.com | www.030628.com | www.2688cai.com | www.www | www.938m.cc | www.hg1733.com | 1483a.com | zb11.com | 0698v.com | 3yuhe.com | www.106395.com | www.hx6692.com | www.743902.com | www.j1432.com | www.rb05.com | www.73800.com | www.223456r.com | gg2649.com | 4025h.com | 1168i.com | 518cp8.com | www.257233.com | www.hc2588.com | www.66332s.com | www.4809t.com | www.89677b.com | www.67007.com | www.56520c.com | q5002.com | ylzz522.com | 38365m.com | 2618l.com | 8381b.com | 5443ee.com | www.202403.com | www.808761.com | www.9155a.com | www.518pj.com | www.hr1555.com | www.47506.cn | www.15k0048.com | www.8967c.com | www.333wh.com | www.236js.com | www.7622900.com | www.pjbet555.com | www.ylg2345.com | www.033033n.com | 83377n.com | 86811h.com | 56132450.com | 6487sss.com | 13222c.com | 5.am | 4231b.com | 3568vv.com | 35222m.com | 70118g.com | xinvip8.com | 5004ee.com | 1389hh.com | 97618w.com | 0969.com | dd3336.com | 54443w.com | 3189uu.com | 77775309.com | 0166e.com | 77606y.com | 3416u.com | hg10d.com | 82365x.com | n67890.com | 35222hh.com | chenyinliang.com | 55335004.com | www.xsj977.com | www.hg988800.com | www.56520s.com | www.flb0033.com | www.fh6000.com | www.21050011.com | www.hg72999.com | www.659200.com | www.9611msc.com | www.50000991.com | www.qq55826.com | www.4996hl.com | www.32031o.com | www.984008.com | www.7239y.com | www.6539x.com | www.178012.com | www.560629.com | www.128760.com | 9895o.com | 5651a.com | 0729a.com | 77260088.com | 2019yy.cc | www.323788.com | www.kelake88.com | www.919205.com | www.294218.com | www.68993278.com | www.083wy.com | www.861944.com | www.292866.com | 78666c.com | c388y.com | 32555t.com | dzjgw9999.com | www.9844js.com | www.32126z.net | www.999530.com | www.9737ss.com | www.56011v.com | www.68568m.com | www.sj119.9slyl.com | www.523780.com | 4123001.com | 3678zzz.com | bbc51133.com | www.67797u.com | www.033008.com | www.huangma25.com | www.13434g.com | www.7777hi.com | www.318016.com | 01234pp.com | a81570.com | 3096.com | www.pj5767.com | www.3846m.com | www.32031q.com | www.33112r.com | www.516113.com | 7874.cc | 9068w.com | bcylc7.com | www.330007.com | www.5181889.com | www.81233q.com | www.381772.com | 44663885.com | x33f.vip | www.58777l.com | www.i92776.com | www.0601h.com | www.543122.com | 15a40.net | 47749z.com | www.333177.com | www.11517ee.com | www.3008553.com | www.w983.com | 5577vn77.com | toucai66.com | www.10050011.com | www.1851132.com | www.9928n.com | www.50080i.com | 655661144.com | 1077oo.com | www.548sunbet.com | www.490805.com | www.c1968.com | 44zz8332.com | 3522a.vip | www.77537a.com | www.7hg6668.com | www.6364q.com | y2894.com | 435797.com | www.995o.net | www.lhg888.com | www.flcb4.com | 569pj.com | e58955.com | www.82508b.com | www.r999997.com | www.595601.com | 38365h.com | nyty02.com | www.5360tt.com | www.60007t.com | 9645nn.com | ssha0004.com | www.xpj2638.com | www.hg77750.com | www.309135.com | 34m35.com | www.hjdc2000.vip | www.130013.com | www.607599.com | 2709m.com | www.vns8896.com | www.58404a.com | www.914906.com | 3522nn.cc | www.7435q.com | www.10999a.com | www.987443.com | 55331m.com | www.986686.com | www.118.ceo | www.609812.com | 756756d.com | www.pj85993.com | www.326213.com | www.178113.com | 33382x.com | www.10340.com | www.62118c.com | 131s.net | www.797xj.com | www.4196d.com | www.316106.com | 35222mm.com | www.665335.com | www.33598g.com | 22ll8332.com | www.y1155.com | www.785409.com | 2247j.com | 2649q.com | www.6776jj.com | www.729937.com | xpj8182.cc | www.xpj1506.com | www.32123w.com | 31n.net | www.3643q.com | www.js7551.com | a4255.com | www.8494v.com | www.765.me | p332.com | www.6808pj.com | www.xingji01.com | 2613a.com | www.g88998.com | www.487bbb.com | 88021.com | www.hg4111.com | www.23456789.pw | 2267j.com | www.85770m.com | www.1115.com | 34545.com | www.8694z.com | www.4323h.com | 3405j.com | www.223aa.net | www.8499m.com | 06385454.com | www.980999.com | www.789755.com | 80850qq.com | www.4694v.com | www.108065.com | 3333xsj.com | www.p94600.com | 876878h.com | www.611msc.com | www.9356r.com | pj00ll.com | www.68277444.com | www.109026.com | 1669t.com | www.8998885.com | 222v22.com | www.902488.com | www.739233.com | ctxcp58.com | www.69567p.com | 895320.com | www.2846hh.com | www.c9220.com | e86811.com | www.u32031.com | 22207g.com | www.hg9940.com | www.c9664.com | chengxinbo.net | www.xyh6001.com | 6112hh.com | www.js815.com | www.442428.com | 1259n.com | www.889601.com | l21148com | www.5099zz.com | 38345c.com | www.aomen8866.com | www.925831.com | 914904.com | www.hg107.com | 1104dh.com | www.50999f.com | kk3397.com | www.8577k.cc | www.196509.com | www.373720.com | www.gai50.com | 2247b.com | www.633547.com | 7240i.com | www.620932.com | 2267g.com | www.n9478.com | 3844u.com | www.449941.com | www.347277.com | www.0636h.com | www.c6348.com | 9895.com | www.2109d.com | yy56988.com | www.80065x.com | 55545r.com | www.89777p.com | hjsxjgj.com | www.3421b.com | 66300vip25.com | www.lhg000.com | 31194444.com | www.7366005.com | o77304.com | www.net567.com | 66681v.com | www.9737dd.com | nnn40033.com | www.4996sh.com | youleseo.com | www.46630.info | 08159t.com | www.x063801.com | 4776600.com | www.89386d.com | a14666.com | www.7036fh.com | pj00ll.com | www.4809d.com | lc99t.com | www.86008.com | 33772007.com | www.25688g.com | 272k.net | www.810277.com | www.365665.com | www.258029.com | www.892099.com | yeba17.com | www.542suncity.com | 1117.com | www.1429e8.com | i14666.com | www.tyc1998689.com | t7742.com | www.89980.cc | www.hg8786.org | www.456836.com | www.js1177.com | dj0001.com | www.klcp385.com | js22888.com | www.hg8.vip | 8449ee.com | www.2934c.com | www.8494t.com | www.062766.com | www.785888.com | 2381ccc.com | www.69567p.com | 983888x.com | www.2109h.com | www.27706.com | ule8.vip | www.5099kk.com | 566777t.com | www.81678y.com | www.pu5555.net | www.269707.com | www.am4567.com | 365vip00.win | lh66k.com | www.696668.com | 3656uu.com | www.64700.com | www.07404.com | 91019u.com | www.bet91488.com | 56987yy.com | www.8039n.com | www.357996.com | 06385757.com | www.673888g.com | 3650329.com | www.c6093.com | www.43012l.com | 5855uu.com | www.ylylc00.com | www.pj57777.com | 32424k.com | www.53097777.com | 0091234.com | www.881809.com | www.779333.com | 9479.com | www.5522l.cc | www.2222k0.com | ww555hg.com | www.37377m.com | www.js87000.com | ss5443.com | www.js58678.com | pj11345.com | www.098303.com | www.8473l.com | 61322288.com | www.332930.com | www.8861tt.com | 838388j.com | www.406577.com | www.1168o.com | 70118p.com | www.567206.com | www.557116.com | 2096u.com | www.374877.com | www.7415f.com | 2649y.com | www.66652a.com | www.578371.com | 88113885.com | jixiang9.com | www.179107.com | www.cr689.com | 8128522.com | www.83033s.com | www.hg8968.com | lh66z.com | www.qmfc2.com | www.80388.com | xpj5004.com | www.449810.com | www.u69096.com | 3168b.com | 2649g.com | www.3301866.com | www.9999304.com | 26668p.com | www.785382.com | www.38345j.com | feicai025.com | js14r.com | www.yh68222.com | www.138ppp.com | 092258.com | www.524077.com | www.7893w36.com | www.pu7777.net | 5804p.com | www.44kcw.com | www.77731f.com | 2267e.com | biying940vip.com | www.80065x.com | www.333980.com | sbobet.com | js648888.com | www.185647.com | www.335666.com | 08159h.com | 30007a.com | www.771478.com | www.20976.com | 2127l.com | 7744aaa.com | www.81678z.com | www.sb005.com | 4023v.com | 67877q.com | www.qmfc2.com | www.16181d.com | www.long6668.com | 27878ee.com | www.587991.com | www.js89q.vip | www.582666.com | 2142299.com | 64898d.com | www.5484d.com | www.4963rr.com | www.hg6364.com | 5360d.com | www.301823.com | www.bet365yazhou.com | www.jb8899.com | 776093.com | rr4255.com | www.515848.com | www.cq58qp.com | www.567771.com | 033k.net | 44077n.com | www.186757.com | www.771478.com | www.85857u.com | www.js69ll.cc | 3566hh.com | wns2.net | www.500lian.com | www.n7764.com | www.ljw036.com | 3522oo.com | 4123zz.com | www.509265.com | www.1108788.com | www.6003p.com | www.wns8858.com | 4488ccc.com | pujingzaixianyule.com | www.3479y.com | www.06386655.com | www.s4158.com | 081965.com | 22254066.com | 3844u.com | www.ct8822.com | www.xpj8816.com | www.047222.com | www.5550105.com | 3550.com | b01311.com | www.330871.com | www.66653m.com | www.38138c.com | www.cs505.com | 22p88.cc | 35222uu.com | 3807n.com | www.517411.com | www.57578b.com | www.69989d.com | www.jb33333.com | www.6491d.com | 473042.com | 99567m.com | 66876g.com | www.652361.com | www.7239h.com | www.n69096.com | www.987111.com | www.76060s.com | 22ss8331.com | 7893w17.com | 861052.com | www.373500.com | www.5522t.cc | www.55717w.com | www.7415f.com | www.6650.bet | www.cr589.com | 4023h.com | 51133oo.com | dd5144.com | 3202g.com | www.401282.com | www.589zf.com | www.28891e.com | www.t80288.com | www.776775.com | www.09569n.com | 74668.com | 366yh.com | 3242f.com | 7742qq.com | 3049w.com | 8180v.com | www.647977.com | www.9155f.cc | www.t509.com | www.42070012.com | www.4058a.com | www.wi444.com | www.7755xj.com | www.pjbet3388.com | a3144.com | 25288f.com | 4556y.com | 407ll.com | 5802dd.com | lixingyoulun.com | 2389900.cc | www.261793.com | www.848966.com | www.065wy.com | www.60108g.com | www.954321v.com | www.792087.com | www.1559506.com | www.5146z9.com | www.938v.cc | www.058767.com | www.789270.com | www.hg3385.com | www.9068oo.com | www.4763222.com | www.d0686.com | 3377vn77.com | hg168y.com | 2190m.com | 2649o.com | 6766bb.com | 84496611.com | v4212.com | 4022x.com | 3957t.com | 8538q.com | 68886508.com | 23300c.com | 00112007.com | bwinfff.com | hjdc678.com | 99589e.net | x333.com | 025902.com | 28758y.com | 0245y.com | jjj5682.com | 9694d.com | 4445.ag | 51133oo.com | 3435k.com | 84496611.com | bet28o.com | 3049y.com | 2019c.cc | lshtq.cn | www.hg45888.com | www.32126x.net | www.benz4433s.com | www.55268ii.com | www.y2205.com | www.3170004.com | www.13090.com | www.77msctyc.com | www.20110.com | www.8883hj.com | www.4058vv.com | www.07679v.com | www.99094y.com | www.4331a.com | www.7239a.com | www.15010.cc | www.ct6679.com | www.611026.com | www.150928.com | 89777t.com | 8381ss.com | 3779955.com | 3522w.cc | 73055d.com | 9566474.com | www.vns3333.cc | www.9101905.com | www.76775c.com | www.8967g.com | www.6687w.com | www.6889792.com | www.50051n.com | www.hx6697.com | www.383571.com | 70766633.com | 2883kf.com | 55717dd.com | 7720v.com | www.68666v.com | www.a30226.com | www.41610.com | www.7415zz.com | www.78680a.com | www.7239g.com | www.hr5888.com | www.235117.com | 8898555.com | 6396x.com | hg77703.com | www.33333jsc.com | www.g32126.cc | www.d4042.com | www.115527f.com | www.790964.com | www.cc6769.com | www.83993e.com | 2081.com | 3467j.am | 51335u.com | www.6suncity.com | www.cp505.com | www.js57666.com | www.66069.cc | www.332709.com | 5906FF.com | 93922x.com | 9030c.com | www.wnsr999.com | www.rgcp111.com | www.3775p.com | www.bei08.com | bwin940.co | ss76669.com | 22kk8331.com | www.hg9922.org | www.kj639.com | www.1764o.com | www.66ffl.com | www.39500v.com | 8159zz.cc | bet8688.net | www.3643b.com | www.50999h.com | www.151228.com | www.598074.com | 3522ww.cc | 4196u.com | www.4123nn.com | www.4907788.com | www.v1028.com | www.yi648.com | 060.com | 6489.am | zz38648.cc | www.js629.com | www.888977.com | www.998632.com | beplay.pub | 7555e.com | www.3332558.com | www.22666.com | www.7239k.com | www.190302.com | 867203.com | 168cp-o.com | www.tk533.com | www.3398755.com | www.730265.com | 048.com | 6245h.com | www.xy5050.com | www.xpj11882.com | www.903559.com | 66300vip06.com | 44488e.com | www.hg8375.com | www.59999.am | www.524277.com | drcp111.com | 1592q.com | www.jy738.com | www.77801f.com | xxxx0128.com | 51133uuu.com | www.4107j.com | www.958.net | www.980221.com | 33432o.com | bb8888b.com | www.mc298.com | www.71399t.com | 2147004.com | mohan2013.com | www.lgf08.com | www.hg735.com | www.298980.com | chunqiu2.com | www.7830z.com | www.40288d.com | www.580820.com | 7616.net | www.8694m.com | www.63606k.com | www.533236.com | bmw8088.com | www.99yh765.com | www.06386655.com | www.606865.com | 0343o.com | www.x27229.com | www.60886k.com | www.514077.com | 3522mm.cc | www.hg5588l.com | www.68993251.com | 1211.com | 473042.com | www.9906132.com | www.50074b.com | 1705o.com | ww666hg.com | www.5446jj.com | www.758786.com | 5504p.com | www.js05888.com | www.hg20.com | 0986.com | spj81.net | www.71071r.com | www.708330.com | 584464.com | www.73999u.com | www.66621d.com | 08159f.com | www.0223889.com | www.wns123f.com | www.109075.com | 87965aa.com | www.138cpr.com | www.937016.com | chunqiu2.com | www.139835.com | www.4923a.com | z32365.com | www.wns8838.com | www.14168e.com | 33933.com | 220414.com | www.1559507.com | www.083016.com | 0600n.cc | www.7415p.com | www.363067.com | hwcp22.com | www.28000j.com | www.346411.com | wxc0126.com | www.80969a.com | www.345839.com | 2247000.com | www.hg8zz.com | www.139733.com | 3245g.com | www.46630.com | k00351.com | 5004gg.com | www.1449.com | 9498.com | www.7893900.com | www.39500hh.com | 118888h.com | www.377088.com | www.5091c.com | 30176611.com | www.87p333.com | www.649880.com | 8569833.com | www.4996ty.com | 11ii8331.com | www.ylhg0808.com | www.4331a.com | 33599bb.com | www.26yh.com | www.959553.com | 444b9.com | www.4058yy.com | 8722hhhh.com | www.76060g.com | www.97655g.com | 7893.cc | www.hg126u.com | www.305388.com | 8030t.com | www.99094x.com | z83377.com | www.xpj180.com | www.763829.com | feicai0536.com | www.12136v.com | 8838000.com | www.aa.1100914.com | www.c6883.com | 50099t.com | www.44118p.com | 89777c.com | www.hg7644.com | www.578113.com | 7610.com | www.038839.com | 5504q.com | www.rycp156.com | 7720776.com | www.hgcn888.com | www.1035g.com | 55797f.com | www.ba502.com | 667766t.com | www.esb116.net | www.091150.com | www.vnsr900.com | www.2632a.com | nn500m.com | www.1764e.com | 2595o.com | www.ggy.99233y.com | hd2629.com | www.370011.com | www.671566.com | js29391.com | www.53900j.com | b4647.com | www.110589.com | 22296ak.com | www.4694o.com | 56988pp.com | www.suncity3.com | 4116d.com | www.js778911.com | www.383571.com |