2016-11-16 123 views
3

enter image description here如何在SQL Server 2014中將整數列轉換爲varchar?

我抄從SQL Server,除了這是後來添加的最後一列(expected_rn_af)的結果。

如何使用SQL Server中的update語句將列rn_af轉換爲expected_rn_af

+0

是從1到9的唯一支持的值?你有查找表,將rn_af轉換爲Expected_Rn_af?你是否有更新聲明,即使它不起作用? –

+0

是否想要在SQL Server中使用新值創建新列,或者是否想要使用更新的值替換當前值?另外,數據的當前結構是什麼? – DForck42

+0

除了下面的其他答案,你有這樣的選項:'substring('ABCDEFGHI',rn_af,1)' – shawnt00

回答

4

添加字符()

Update YourTable 
    Set Expected_Rn_af = char(64+rn_af) 
+1

哈,有趣的方法。 +1 – scsimon

0

看起來你想要一個case語句中的64 + rn_af ...

... 
case 
    when rn_af = 1 then 'A' 
    when rn_af = 2 then 'B' 
    ... 
end as expected_rn_af 
相關問題