如何在SQL查询中将数字转换为文本 [英] How to Convert numbers to text in SQL Query
问题描述
我有一个SQL查询,我想知道是否可以转换行号,我的结果显示为0,1,2,每列3或4个。
是否可以显示这样的内容?
0 =在客户处注销
1 =返回原始GRN
2 =仅退款
3 =返回新GRN
4 =反向发票
Hi,
I have a SQL query where I would like to know is it possible to convert line number which in my result shows 0,1,2,3 or 4 on each column.
is it possible to show something like this?
0 =Write off at Customer
1 =Return to Original GRN
2 =Refund Only
3 =Return to New GRN
4 =Reverse Invoice
SELECT CreditRequest.TheirReference, CreditRequestLine.LineType, CreditRequest.CreditRequestNumber
FROM CreditRequest INNER JOIN
CreditRequestLine ON CreditRequest.CreditRequestID = CreditRequestLine.CreditRequestID
行ID
2
3
1
2
4
Line ID
2
3
1
2
4
推荐答案
是。
最好的方法是设置一个单独的表:
Yes.
The best way to do it is to set up a separate table:
ResultCodes
ResId (INT) Desc(NVARCHAR)
0 Write off at Customer
1 Return to Original GRN
2 Refund Only
3 Return to New GRN
4 Reverse Invoice
然后使用SQL JOIN返回数据
You then use an SQL JOIN to return the data
SELECT a.Customer, b.Desc FROM MyTable a
JOIN ResultCodes b
ON a.Res=b.ResId
您可以很容易地将它与现有查询结合起来 - 我不知道你的哪个领域是什么,所以我不能为你做到这一点!
You can probably combine that with your existing query pretty easily - I have no idea what field of yours is what so I can't do that for you!
这篇关于如何在SQL查询中将数字转换为文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!