当前位置: 代码迷 >> Sql Server >> 请问,SQL语句在包含.的中增加一个字符
  详细解决方案

请问,SQL语句在包含.的中增加一个字符

热度:45   发布时间:2016-04-27 11:20:55.0
请教,SQL语句在包含.的中增加一个字符
表A

姓名 学历
张三 小学0.
李四 初中.
王麻子 大学

请教如何在学历包含‘.‘中增加 字符"无效'

使用 WHHERE 一个条件可以 ,但是如果使用LIKE ‘%.’ 会报错说 :
将截断字符串或二进制数据。
语句已终止。

请教其他方法

------解决方案--------------------
SQL code
update tb set 学历=学历+'无效' where charindex('.',学历)>0
------解决方案--------------------
SQL code
declare @t table ( [姓名] nvarchar(4),  [学历] varchar(8) )insert into @tselect '张三','小学0.' union allselect '李四','初中.' union allselect '王麻子','大学' select *,    case when charindex('.',[学历],0) >=1 then '无效' else [学历] end from @t--------------------------(3 行受影响)姓名   学历       ---- -------- --------张三   小学0.     无效李四   初中.      无效王麻子  大学       大学(3 行受影响)
------解决方案--------------------
SQL code
------------------------------ Author  :fredrickhu(小F,向高手学习)-- Date    :2012-07-12 10:27:32-- Version:--      Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (Intel X86) --    Apr 22 2011 11:57:00 --    Copyright (c) Microsoft Corporation--    Enterprise Edition on Windows NT 6.1 <X64> (Build 7600: ) (WOW64)--------------------------------> 测试数据:[a]if object_id('[a]') is not null drop table [a]go create table [a]([姓名] varchar(6),[学历] varchar(100))insert [a]select '张三','小学0.' union allselect '李四','初中.' union allselect '王麻子','大学'--------------开始查询--------------------------update a set 学历=学历+'无效' where charindex('.',学历)>0select * from a----------------结果----------------------------/* 姓名     学历------ ----------------------------------------------------------------张三     小学0.无效李四     初中.无效王麻子    大学(3 行受影响)*/
  相关解决方案