日期:2014-05-18  浏览次数:20334 次

求一条sql语句【获取某列数字】
求一条sql语句【获取某列数字】

if exists (select * from sysobjects where id = OBJECT_ID('[tb_test]') and OBJECTPROPERTY(id, 'IsUserTable') = 1) 
DROP TABLE [tb_test]

CREATE TABLE [tb_test] (
[col] [nchar] (10) NULL)

INSERT [tb_test] ([col]) VALUES ( N'2个')
INSERT [tb_test] ([col]) VALUES ( N'2只')
INSERT [tb_test] ([col]) VALUES ( N'3块')
INSERT [tb_test] ([col]) VALUES ( N'无')
INSERT [tb_test] ([col]) VALUES ( N'4块')

select [col] from [tb_test]


要求 获取的值 为


col


2
2
3
0
4
-------------------
没有数字的 都是 0,请不要用substring 函数


------解决方案--------------------
select left(right('00'+[col],2),1)
from [tb_test]
-- 要看最后的单位是不是都是一个的情况。