create table tblInput(id int identity(1,1),Input varchar(10),Address varchar(10),NewName as case when Input in('智能五笔','万能五笔','王码五笔') then '五笔' else 'client' end)
create table #t (ID varchar(10),Input varchar(10),Address varchar(10),NewName as case when input in ('智能五笔','万能五笔','王码五笔') then '五笔' else 'Client' end )insert into #t (id,input,address) values('1','dd','dd')insert into #t (id,input,address) values('1','万能五笔','dd') select * from #t
--方法1. 用计算列 create table tblInput(id int identity(1,1) ,Input varchar(10) ,Address varchar(10) ,NewName as case when Input in('智能五笔','万能五笔','王码五笔') then '五笔' else input end)--方法2. 用视图 create view v_tblInput as select id,Input,Address,NewName=case when Input in('智能五笔','万能五笔','王码五笔') then '五笔' else input end from tblInput
create table #t (ID varchar(10),Input varchar(10),Address varchar(10),NewName as case when input in ('智能五笔','万能五笔','王码五笔') then '五笔' else input end )insert into #t (id,input,address) values('1','智笔','dd')select * from #t
--下面是例子:--方法1. 用计算列 create table tblInput(id int identity(1,1) ,Input varchar(10) ,Address varchar(10) ,NewName as case when Input in('智能五笔','万能五笔','王码五笔') then '五笔' else input end) go--插入数据 insert into tblInput select '智能五笔','111' union all select '其他','222'--显示结果 select * from tblInput go/*--测试结果 id Input Address NewName ----------- ---------- ---------- ---------- 1 智能五笔 111 五笔 2 其他 222 其他(所影响的行数为 2 行) --*/--删除测试表 drop table tblInput
--下面是例子:--方法2. 用视图 --原始表 create table tblInput(id int identity(1,1) ,Input varchar(10) ,Address varchar(10)) go--用视图 create view v_tblInput as select id,Input,Address,NewName=case when Input in('智能五笔','万能五笔','王码五笔') then '五笔' else input end from tblInput go--插入数据 insert into tblInput select '智能五笔','111' union all select '其他','222'--显示结果 select * from v_tblInput go--删除测试表 drop table tblInput drop view v_tblInput /*--测试结果 id Input Address NewName ----------- ---------- ---------- ---------- 1 智能五笔 111 五笔 2 其他 222 其他(所影响的行数为 2 行) --*/
create table #t (ID varchar(10),Input varchar(10),Address varchar(10),NewName
as case when input in ('智能五笔','万能五笔','王码五笔') then '五笔' else 'Client' end )insert into #t (id,input,address) values('1','dd','dd')insert into #t (id,input,address) values('1','万能五笔','dd')
select * from #t
newname不需要建在(永久)表里。需要时查询生成就行了。
create table tblInput(id int identity(1,1)
,Input varchar(10)
,Address varchar(10)
,NewName as case when Input in('智能五笔','万能五笔','王码五笔') then '五笔' else input end)--方法2. 用视图
create view v_tblInput
as
select id,Input,Address,NewName=case when Input in('智能五笔','万能五笔','王码五笔') then '五笔' else input end
from tblInput
as case when input in ('智能五笔','万能五笔','王码五笔') then '五笔' else input end )insert into #t (id,input,address) values('1','智笔','dd')select * from #t
create table tblInput(id int identity(1,1)
,Input varchar(10)
,Address varchar(10)
,NewName as case when Input in('智能五笔','万能五笔','王码五笔') then '五笔' else input end)
go--插入数据
insert into tblInput
select '智能五笔','111'
union all select '其他','222'--显示结果
select * from tblInput
go/*--测试结果
id Input Address NewName
----------- ---------- ---------- ----------
1 智能五笔 111 五笔
2 其他 222 其他(所影响的行数为 2 行)
--*/--删除测试表
drop table tblInput
--原始表
create table tblInput(id int identity(1,1)
,Input varchar(10)
,Address varchar(10))
go--用视图
create view v_tblInput
as
select id,Input,Address,NewName=case when Input in('智能五笔','万能五笔','王码五笔') then '五笔' else input end
from tblInput
go--插入数据
insert into tblInput
select '智能五笔','111'
union all select '其他','222'--显示结果
select * from v_tblInput
go--删除测试表
drop table tblInput
drop view v_tblInput
/*--测试结果
id Input Address NewName
----------- ---------- ---------- ----------
1 智能五笔 111 五笔
2 其他 222 其他(所影响的行数为 2 行)
--*/
我用happydreamer(卖女孩的小火柴)的方法实现了,所以多给一些分(30)。
谢谢zjcxc(邹建) ,你让我学到了很多东西,谢谢了,^^,给你20分,不要嫌少哦。
happydreamer(卖女孩的小火柴)的方法.算
没看清你开始的回答,不好意思啦,下次给你多点,^^