‘壹’ 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