Teacher 表    字段 ID,TeaNo,nameStudent 表    字段 ID,StuNo,nameParent  表    字段 ID,ParNo,nameCard    表    字段 ID,No---------------------------------------------
实现功能通过 No  获得 name例如  输入 XS01-----> 输出 张三
      输入 JZ01-----> 输出 李四
      输入 JS01-----> 输出 王五名称为dbo.getName(No)

解决方案 »

  1.   

    你的name来自于来个表
    要说清楚吧
      

  2.   

    各个表之间的关系是怎么样的?通过ID获取哪个name?
      

  3.   


       三张表 都有字段 name    现在我要 输入一个编号(编号可能是 教师 可能是 家长 或者学生的) 得到他们的名字
      

  4.   


      Card  表的 No 存储的是 三张表内所有的编号信息
      

  5.   


    select * from Teacher where ID in (select ID from Card where No='对应的值')
    union all
    select * from Student where ID in (select ID from Card where No='对应的值')
    union all
    select * from Parent where ID in (select ID from Card where No='对应的值')
      

  6.   

    create function dbo.GetName(@No varchar(20))
    returns varchar(50) as
    begin
       declare @vcReturnValue varchar(50)
       set @vcReturnValue=''
       select @vcReturnValue=[name]
              from (select TeaNo as 'No',[name] from Teacher union
                    select StuNo as 'No',[name] from Student union
                    select ParNo as 'No',[name] from Parent) as t
              where t.[No]=@No
       return @vcReturnValue
    end
      

  7.   


    create function FC_GetTable(@No nvarchar(20))
    returns table
    as
    return
    (
     select * from Teacher where ID in (select ID from Card where No=@No)
    union all
    select * from Student where ID in (select ID from Card where No=@No)
    union all
    select * from Parent where ID in (select ID from Card where No=@No)
    )