select CONVERT(varchar(50),id+1-(select min(id) from
b where inportdate='20091013' and sp_id='tu')) from a
现想得出,如果查得结果位数为1则前面补00,位数为2刚补一0,否则取原数要怎样写?
b where inportdate='20091013' and sp_id='tu')) from a
现想得出,如果查得结果位数为1则前面补00,位数为2刚补一0,否则取原数要怎样写?
解决方案 »
- 收藏 我想insert一个datetime字段,该怎么写格式。。。。
- sql语法的问题,超难!!!紧急求助~~~~~~~
- SqlServer 与 MySql 的 sql 语句最大的区别
- 极度郁闷,万分痛苦,sql server的问题
- sql语法基本问题
- SQL2008 无法连接到XXX error 40 MS SQL 错误2
- 在SSIS的数据流执行过程中,执行到9900多行的时候程序停了下来,没有完成也没有错误信息。
- 这个表该如何设计?请有经验的人指点。
- 如何查询日期等于2004-1-2记录,我的条件是2004-01-02,要让2004-01-02
- 存储过程嵌套的问题
- 请教!请多关照,sql分页语句
- 爱新觉罗.毓华 如何 你指定的驱动无效,或是没有安装.
b where inportdate='20091013' and sp_id='tu')),3)AS C from a
when = 2 then '0' + '结果'
when = 1 then '=0' + '结果'
end
要不然用
CASE WHEN 来判断
(
select
CONVERT(varchar(50),id+1-(select min(id)
from
b
where
inportdate='20091013' and sp_id='tu')) as id
from
a
)
select id=case when len(id)=1 then '00'+cast(id as varchar)
when len(id)=2 then '0'+cast(id as varchar)
when len(id)=3 then cast(id as varchar) end
b where inportdate='20091013' and sp_id='tu')),3) from a
b where inportdate='20091013' and sp_id='tu')) from a
select right('000'+CONVERT(varchar(50),id+1-(select min(id) from
b where inportdate='20091013' and sp_id='tu')),3) from a
select isnull(replicate('0',3-len(s)),'')+ltrim(s)
from
(
select
CONVERT(varchar(50),id+1-(select min(id)
from b
where inportdate='20091013'
and sp_id='tu')
) s
from a
)t