『壹』 sql替換查詢結果字元串中的字元
用replace函數將年,月替換成橫杠,日替換成空,從而形成tb的標准日誌格式,然後再做比較。這里給出replace的示例:
select replace(replace(REPLACE('2017年01月01日', '年', '-'), '月', '-'), '日', '')
注: 此replace函數在SQL Server資料庫上適用,其他資料庫可能要做相應調整。
『貳』 sql如何把查詢到的NULL替換成空值
1、這要看你如何保存你查詢的結果。只能是你把你查詢的結果保存為0,查詢不會改變原本存在的值。表名test,欄位a=.null.(int型),欄位b=1,欄位c=2 :select * from test into tabel test1
update set a=0 where a=.null。
2、用 IsNull(欄位名, '') 可以將NULL的欄位轉換為空值,這在多個欄位連接時很有用,因為NULL值+任何欄位都是NULL。
3、將NULL替換為空create procere fill_null@tablename varchar(100) --表名asdeclare @colname varchar(100)declare col_cur cursor for select c.name from syscolumns c,sysobjects o where c.id=o.id and o.name=@tablename open col_curfetch next from col_cur into @colnamewhile @@fetch_status!=-1beginexec ('update '+@tablename+' set '+@colname+'='''' where '+@colname+' is null' )fetch next from col_cur into @colnam endclose col_curdeallocate col_cur
『叄』 SQL批量查詢和替換
1.把新的結果集在xls文件中做好,保存文件.
2.在資料庫中新建一個存儲新數據並用於替換的表.
用create
table,或者select
into
...where
1<>1克隆.
3.將xls文件數據批量導入資料庫新表.
4.用聯表更新語句,將新表數據更新到表中.
5.drop
table
語句刪除臨時用的存儲表.
---------
此語句用於mssql批量導入,注意在導入時文件需處於關閉.
例:insert
into
TableName(Column1,Column2,Column3,Column4)
select
Column1,Column2,Column3,Column4
from
OpenDataSource
(
'Microsoft.Jet.OLEDB.4.0',
'Data
Source="Path\FileName.xls";User
ID=Admin;Password=;Extended
properties=Excel
5.0'
)...sheet1$
『肆』 SQL查詢結果替換
select * from 表 where 欄位 like '%+%'
--查詢某個欄位里是否有結果包含'+'的
update 表 set 欄位 = replace(欄位,'+','') where 欄位 like '%+%'
--更新上句查詢出來了。若有多個欄位,且你不確定'+'出現的欄位,可每個欄位分別執行這兩句。
『伍』 SQL條件查詢替換
update news set CONTEMT= REPLACE ( CONTEMT,'HTM', 'HTM1') where type=40
解釋:
update 表名 set 欄位名= REPLACE ( 欄位名,'被替換的值', '替換成') where 條件
『陸』 如何用sql語句把查詢後的結果那一列數據全部替換。
在oracle中
select cou1,cou2,cou3,decode(sign(cou4-10),-1,decode(sign(cou4-1),1,a,cou4),cou4) from table
在這個之中就是decode函數的使用,decode(條件,值1,翻譯值1,值2,翻譯值2,...值n,翻譯值n,預設值),相當於if的使用,sign()函數根據某個值是0、正數還是負數,分別返回0、1、-1。decode(sign(cou4-10),-1,decode(sign(cou4-1),1,a,cou4),cou4)這句話的解釋是如果cou4的欄位值減10為負數並且cou4的欄位值減1為正數的話值為a,反之則為cou4的欄位值。。
『柒』 求教,sql 查詢後替換語句!
updatetable
set分類=2
where關鍵詞like'%襯衫%'
不知道是不是你想要的結果?
『捌』 SQL將查詢結果中的值批量替換為其它值
mysql的話:
update表1a,表2b,表2cseta.BatchID=b.name,a.PlanNature=c.namewherea.BatchID=b.BatchIDanda.PlanNature=c.BatchID
你第二個表沒給欄位名,第三列我這邊定義為BatchID,第四列定義為name。
執行前備份表1
『玖』 sql查詢結果部分替換
有辦法的,不過要慎用
先為表1增加兩個欄位,一個是begin_name 一個是end_name
然後update這兩個欄位
替換為第三個欄位里的前4位和後4位,用substr函數
再然後拼接一下字元串替換一下
最後把新增的兩個欄位弄掉
----------------補充-------------
具體步驟
1.alter table 表1 add begin_name varchar2(24) NULL;
alter table 表1 add end_name varchar2(24) NULL;
長度自己定義,足夠長就行,以後這里要存放表2的欄位3
2.update 表1 set begin_name=substr(欄位3,1,4);
update 表1 set end_name=substr(欄位3,-4,4);
commit;
3.update 表1 a set a.begin_name=(select b.欄位3 from 表1 b where a.字 段1=b.欄位1);
update 表1 a set a.end_name=(select b.欄位3 from 表1 b where a.欄位1=b.欄位1);
commit;
4.update 表1 set 欄位3=begin_name||'~'||end_name;
commit;
5.drop那倆欄位,這個不用我寫了吧?
還有點問題,如果象你第三條紀錄,那你就判斷一下欄位3的長度就行了,這個改起來又不難
我寫的很詳細了啊,你只要把表1表2和欄位名換成你自己資料庫里的不就行了嗎
『拾』 SQl 里 如何替換查詢結果
--so easy
select case when sexy=1 then '男' else '女' end as '性別',*
from table