【发布时间】:2014-03-04 05:32:18
【问题描述】:
我的 sql 查询为:
select UJIdentifyer,RecordIdentity,Location,DeptTime,BayNumber,TimingPointIndicatior,
FareStageIndicatior
from QO where UJIdentifyer='139013'
在这个查询的结果中,每一列的值长度都是固定的。
例如。 Location 列的长度必须为 12 个字符。
如果是 11 则填一个空格,如果是 10 则填 2 个空格。
为此我写了:
select UJIdentifyer,case when len(RecordIdentity)=11 then RecordIdentity+''else when len(RecordIdentity)=10 then RecordIdentity+' '.... from QO where UJIdentifyer='139013'
像这样我将不得不写 10-12 个案例来进行长度匹配。
有什么办法可以避免类似情况的重复??
【问题讨论】:
标签: sql sql-server tsql sql-server-2005