这是网上收的列子的应用:
select a.name as [column],b.name as type
from syscolumns a,systypes b
where a.id=object_id('dbo.HR_Employee') and a.xtype=b.xtype and a.name='EE_EmpNo'dbo.HR_Employee(表名) EE_EmpNo(列名) 结果:
    column        type
    EE_EmpNo nvarchar
    EE_EmpNo sysname但是表中实际字段只有 EE_EmpNo nvarchar 请问另一条语句是来自哪,还有望大虾解读一下上面代码的意思!如果我只想去当前表中有的字段那个改怎么写?望高手点拨下,先谢了...

解决方案 »

  1.   

    select a.name as [column],b.name as type
    from syscolumns a,systypes b
    where a.id=object_id('dbo.HR_Employee') and a.xtype=b.xtype and a.name='EE_EmpNo'
    and a.xtype='u'
      

  2.   

    你只设置了  a.xtype=b.xtype ,并没有对 b 表进行其他限制,因此,只要是 xtype = 你的那个列的 xtype ,都会被查询到,当然会多出行来了.
    就比如,主表
    id col
    1  'aaa'
    从表
    id,col2
    1,'fsd'
    1,'vew'
    用id连接查询不就是两条记录嘛.
      

  3.   


    select a.name as [column],b.name as type
    from syscolumns a,systypes b
    where a.id=object_id('tb') and a.xusertype=b.xusertype and a.name='column'
    TRY
      

  4.   


    执行一下这个:
    select xtype,count(*) from systypes group by xtype having count(*)>1
    你就知道了.
      

  5.   

    首先谢谢各位大虾的慷慨解答。SQL777的第一条回答却是是我想要的答案!学习了...