
正文
sqlserver补空行,sql server删除空行
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
sqlserver 中,如何查询把缺少数据自动填补出来,下图中缺少2013-05-27 19:00:00.000 130.4560000000
问题分析:您要的结果是要每一小时一条记录,补充添写中间间隔一小时以上的记录。并且不另增加记录:
问题解决:找到每一条记录时间加1小时在表中不存在的记录,然后加一小时填入表中,不包括最后(最大的)的时间。
3.语句实现(两种方案):
以下语句可以在每一个缺少的数据后加入一小时后填入,但间隔更大(超过2小时后就不行了):
insert into tablename
select fieldtime=dateadd(hh,1,fieldtime),fieldnum from tablename a
where not exists(select 1 from tablename b where dateadd(hh,1,a.fieldtime)=b.fieldtime)
and a.fieldtime!=(select max(fieldtime) from tablename)--去掉最后的时间
以下方案可以完成补充间隔数小时的记录:将该语句循环执行,直到没有记录更改。
insert into tablename
select fieldtime=dateadd(hh,1,fieldtime),fieldnum from tablename a
where not exists(select 1 from tablename b where dateadd(hh,1,a.fieldtime)=b.fieldtime)
and a.fieldtime!=(select max(fieldtime) from tablename)--去掉最后的时间
while @@rowcount0
select fieldtime=dateadd(hh,1,fieldtime),fieldnum from tablename a where not exists(select 1 from tablename b where dateadd(hh,1,a.fieldtime)=b.fieldtime) and a.fieldtime!=(select max(fieldtime) from tablename)
相关问答
Q1: sql 导出为word时好多空行怎么删除?
应该是空格编码不同的原因吧,你们用的是什么输入编辑器啊,在导入到SQLSERVER的时候把空格的编码处理一下应该就可以了。如果不行就换一个编辑器。
Q2: 如何自动补全SQLSERVER表中的属性?
如果表中的 id 列是一个增量列,则要插入的数据包括 id 列的值,设置 identity table on; 插入到 table (id,xxx,... ,xxx) values (id column value,xxx,... ,xxx) ; -- 注意: 这里不能省略字段名。设置身份表;
Q3: sqlserver有没有办法在字段右边加空格?
只要原字段是字符型,直接加没有问题的。只是不知作何用。
select yourfileds + space(n) from yourtable






