問(wèn)題分析:您要的結(jié)果是要每一小時(shí)一條記錄,補(bǔ)充添寫(xiě)中間間隔一小時(shí)以上的記錄。并且不另增加記錄:

為正定等地區(qū)用戶(hù)提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及正定網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、正定網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專(zhuān)業(yè)、用心的態(tài)度為用戶(hù)提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶(hù)的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!
問(wèn)題解決:找到每一條記錄時(shí)間加1小時(shí)在表中不存在的記錄,然后加一小時(shí)填入表中,不包括最后(最大的)的時(shí)間。
3.語(yǔ)句實(shí)現(xiàn)(兩種方案):
以下語(yǔ)句可以在每一個(gè)缺少的數(shù)據(jù)后加入一小時(shí)后填入,但間隔更大(超過(guò)2小時(shí)后就不行了):
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)--去掉最后的時(shí)間
以下方案可以完成補(bǔ)充間隔數(shù)小時(shí)的記錄:將該語(yǔ)句循環(huán)執(zhí)行,直到?jīng)]有記錄更改。
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)--去掉最后的時(shí)間
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)
應(yīng)該是空格編碼不同的原因吧,你們用的是什么輸入編輯器啊,在導(dǎo)入到SQLSERVER的時(shí)候把空格的編碼處理一下應(yīng)該就可以了。如果不行就換一個(gè)編輯器。
如果表中的 id 列是一個(gè)增量列,則要插入的數(shù)據(jù)包括 id 列的值,設(shè)置 identity table on; 插入到 table (id,xxx,... ,xxx) values (id column value,xxx,... ,xxx) ; -- 注意: 這里不能省略字段名。設(shè)置身份表;
只要原字段是字符型,直接加沒(méi)有問(wèn)題的。只是不知作何用。
select yourfileds + space(n) from yourtable
文章題目:sqlserver補(bǔ)空行,sql server刪除空行
本文鏈接:http://chinadenli.net/article18/dsepedp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供、品牌網(wǎng)站制作、企業(yè)建站、靜態(tài)網(wǎng)站、Google、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)