繁体   English   中英

在SQL查询的选择情况下从int值获取文本

[英]get text from int value in select case of sql query

我需要将int值转换为供人类阅读的字符串值选择。

我尝试两种形式,但任何作品

select id, case Preparacion  when 1 then 'Yes' when 0 then 'No' else preparacion end as   Preparación
from pinchos 
inner join Laboratorios on Laboratorios.CodKais = Pinchos.codKais 
where entradaproduccion = '20140905'

并将Preparacion转换为varchar()

select id, case convert(varchar(1),Preparacion)  when '1' then 'Yes' when '0' then 'No' else preparacion end as Preparacion
from pinchos 
inner join Laboratorios on Laboratorios.CodKais = Pinchos.codKais 
where entradaproduccion = '20140905'

如何显示字符串值?

我只读取数据库中的权限,而没有Preparación表

比较为INT并在需要时进行强制转换。

试试这个:(未经测试的代码)

select  id, 
        case Preparacion 
            when 1 then 'Yes' 
            when 0 then 'No' 
            else CAST(preparacion as VARCHAR(255)) 
        end as Preparacion
from pinchos 
inner join Laboratorios on Laboratorios.CodKais = Pinchos.codKais 
where entradaproduccion = '20140905'

你忘了那里的另一个

选择编号,区分大小写
当1时为'是', 否则为 0时则为'否'否则preparacion结束时来自pinchos内部的Preparación加入Laboratorios.CodKais = Pinchos.codKais,其中entradaproduccion ='20140905

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM