[已解决]如何在Sql Query中将数字更改为单词?
问题描述:
我希望显示ststus列的值为1,2,3。这里
1表示待定,2表示已批准,3表示被拒绝。
但是如何在gridview中显示数字而不是用correspoding替换这个数字
words?
I want display ststus column with values 1,2,3. Here
1 indicates Pending,2 indicates approved, and 3 indicates rejected.
But instead of displaying numbers in gridview how can I replace this with correspoding
words?
答
它的简单你可以在你的SQL查询中使用Case。
这里例如现在我使用字段名称作为状态
Its simple you can use Case in your sql query.
here for example now iam using the field name as Status
Select Status, case When status =1 Then 'Pending'
When status =2 then 'approved'
When status =3 then 'rejected'
else 'noStatus' END as 'Status'
from
TableName
在SQL查询中使用CASE
Use CASE in sql query
CASE column_name
WHEN 1 THEN Pending
WHEN 2 THEN Approved
WHEN 3 THEN Rejected
END
尝试:
Try:
SELECT CASE ststus
WHEN 1 THEN 'Pending'
WHEN 2 THEN 'Approved'
WHEN 3 THEN 'Rejected'
ELSE 'ERROR'
END
FROM MyTable