日期:2014-05-17  浏览次数:20659 次

60进制如何转换?怎么编个函数?
分钟转换为小时,标准格式为

将60转换为1.00
70转换为1.10
119转换为1.59
120转换为2.00
1800转换为30.00
1800转换为300.00

------解决方案--------------------
SQL code
select cast(ltrim(@i/60)+'.'+ltrim(@i%60) as decimal(18,2))

------解决方案--------------------
借4楼数据一用
SQL code
IF NOT OBJECT_ID('[tb]') IS NULL
    DROP TABLE [tb]
GO
CREATE TABLE [tb]([col] INT)
INSERT [tb]
SELECT 60 UNION ALL
SELECT 70 UNION ALL
SELECT 119 UNION ALL
SELECT 120 UNION ALL
SELECT 1800 UNION ALL
SELECT 18000
GO

select cast(col/60+(col%60)/100.0 as dec(18,2))
from tb

/**

---------------------------------------
1.00
1.10
1.59
2.00
30.00
300.00

(6 行受影响)
**/

------解决方案--------------------
CAST(COL*1./60 AS DEC(18,2))
------解决方案--------------------
SQL code
--------------------SQL Server数据格式化工具-------------------
---------------------------
-- DESIGNER :happycell188(喜喜)
--       QQ :584738179
-- Development Tool :Microsoft Visual C++ 6.0    C Language 
-- FUNCTION :CONVERT DATA TO T-SQL
---------------------------
-- Microsoft SQL Server  2005
-- Developer Edition on Microsoft Windows XP [版本 5.1.2600]
---------------------------
---------------------------

use test
go
if object_id('test.dbo.tb') is not null drop table tb
-- 创建数据表
create table tb
(
cnt int
)
go
--插入测试数据
insert into tb select 60
union all select 70
union all select 119
union all select 120
union all select 1800
union all select 18000
go
--代码实现
select str(ltrim(cnt/60)+'.'+ltrim(cnt%60),10,2)cnt from tb

/*测试结果

cnt
---------------------
      1.00
      1.10
      1.59
      2.00
     30.00
    300.00

(6 行受影响)
*/