如何比较字段是否以字母或数字开头

时间:2019-07-08 18:58:32

标签: sql sql-server-2008

我想比较一个字段是字母还是数字开头。

Example.

Location.
234848383
664646663
322327772
678862622
HONDURAS
272828833
BRAZIL
PANAMA
UNITED KINGDOM
232332222

这是我当前的查询

SELECT
    dateho.UnitSysId,
    tempvehi.LicencePlate as Economico,
    case when SUBSTRING(prm_dcs.Tipo,1,1) in (1,2,3,4,5,6,7,8,9,0) then 'Heavy' else 'Not heavy' end as Tipo,
            ROUND((dateho.MaxHorasUsoAcumulada - (dateho.MinHorasUsoAcumulada - dateho.MinHorasUso)), 2) as HorasDeUsoMotorPrd
    into #final_table
FROM
    #DatosOdoHoro dateho INNER JOIN #tmpVehiclesAllAccount tempvehi ON dateho.UnitSysId = tempvehi.UnitSysId
                         INNER JOIN PRM.dbo.[prm_DetalleCamiones_Sabana_Estandar] prm_dcs on dateho.UnitSysId = prm_dcs.UnitSysId --AND prm_dcs.UnitSysId= 272729870
ORDER BY
    UnitSysId

你能帮我吗?

谢谢。

2 个答案:

答案 0 :(得分:0)

如果您只是想确定字符串是否以数字开头,那么

case when SUBSTRING(prm_dcs.Tipo,1,1) in (1,2,3,4,5,6,7,8,9,0) then 'Heavy' else 'Not heavy' end as Tipo

可以写为:

case when prm_dcs.Tipo like '[0-9]%' then 'Heavy' else 'Not heavy' end as Tipo

答案 1 :(得分:0)

object Constants {
    const val APP_VERSION = "0.1.0"
}