create table tblInput(id int identity(1,1),Input varchar(10),Address varchar(10),NewName as case when Input in('智能五笔','万能五笔','王码五笔') then '五笔' else 'client' end)

解决方案 »

  1.   


    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
      

  2.   


    newname不需要建在(永久)表里。需要时查询生成就行了。
      

  3.   

    对不起,上面一个小错误:最后的Client应该是Input,也就是说,当Input的值为几种五笔的输入方法时,NewName的值是“五笔”,否则值是Input的值。我希望是通过触发器来解决,请问各位大侠如何实现?
      

  4.   

    --方法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
      

  5.   

    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
      

  6.   

    --下面是例子:--方法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
      

  7.   

    --下面是例子:--方法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 行)
    --*/
      

  8.   

    谢谢各位了!
    我用happydreamer(卖女孩的小火柴)的方法实现了,所以多给一些分(30)。
    谢谢zjcxc(邹建) ,你让我学到了很多东西,谢谢了,^^,给你20分,不要嫌少哦。
      

  9.   

    呵呵,第一个回复是我,我的第一个回复也即是:
    happydreamer(卖女孩的小火柴)的方法.算
      

  10.   

    to:zjcxc(邹建)
    没看清你开始的回答,不好意思啦,下次给你多点,^^