MSSQL中计算两个日期之间相隔 xx天xx小时xx分xx秒
DECLARE @dt1 AS datetime, @dt2 AS datetime;
SELECT @dt1 = '2008-8-4 9:36:41', @dt2 = '2008-8-2 9:33:39';
DECLARE @Days AS int, @Hours AS int, @Minutes AS int, @Seconds AS int;
SET @Seconds = DATEDIFF( second, @dt2, @dt1);
SET @Days = @Seconds / (24 * 60 * 60)
SET @Seconds = @Seconds - @Days * 24 * 60 * 60
SET @Hours = @Seconds / (60 * 60);
SET @Seconds = @Seconds - @Hours * 60 * 60
SET @Minutes = @Seconds / 60;
SET @Seconds = @Seconds - @Minutes * 60;
SELECT CONVERT(varchar(10), @Days ) + '天'
+ CONVERT(varchar(10), @Hours ) + '小时'
+ CONVERT(varchar(10), @Minutes ) + '分'
+ CONVERT(varchar(10), @Seconds ) + '秒';
相关文档:
今天在聊天系统中需要系统执行一个多层嵌套查询。
一开始语句如下总出现错误:原来是在]='123') 后我多加了一个 as tb1
改为如下后,正确运行。
select * from ( select top(10) * from ( select top(100) * from (select [chatcontent].[senderid],[chatcontent].[id] ,[chatcontent].[toid] ,[chatc ......
数据类型
类型
描述
bit
整型
bit 数据类型是整型,其值只能是0、1或空值。这种数据类型用于存储只有两种可能值的数据 ,如Yes 或No、True 或Fa lse 、On 或Off
int
整型
int 数据类型可以存储从- 231( ......
从mssql6.5开始,微软提供了两个不公开,非常有用的系统存储过程sp_MSforeachtable和sp_MSforeachdb,用于遍历某个数据库的每个表和遍历DBMS管理下的每个数据库。
我们在master数据库里执行下面的语句可以看到两个proc详细的代码
use master
exec sp_helptext sp_MSforeachtable
exec sp_helptext sp_Msforeachdb
sp_M ......
--字段添加说明
EXEC sp_addextendedproperty 'MS_Description', '要添加的说明', 'user', dbo, 'table', 表名, 'column', 列名
--删除字段说明
EXEC sp_dropextendedproperty 'MS_Description', 'user', dbo, 'table', 表名, 'column', 字段名
--查看字段说明
SELECT
[Table Name] = i_s.TAB ......
查询语句只要这样写,就可以随机取出记录了
SQL="Select top 6 * from Dv_bbs1 where isbest = 1 and layer = 1 order by newID() desc"
在ACCESS里
SELECT top 15 id from tablename order by rnd(id)
SQL Server:
Select TOP N * from TABLE Order By NewID()
Access:
Select TOP N * from TABLE Order By Rnd(ID ......