CREATE   PROCEDURE SPty_list
@name varchar(20)
 AS
select danganxuhao from TY_danganxuhao where xuhao in  
(select quanxian from UserTable where name=@name)
GO
UserTable 表
quanxian(varchar)    name(varchar)
001,008               ty
008,010                t
TY_danganxuhao 表
xuehao(char)   danganxuhao(varchar)
001             adfsadf
002             asdfasdf
003             asdfasdf
怎么不好使啊

解决方案 »

  1.   

    CREATE   PROCEDURE SPty_list
    @name varchar(20)
     AS
    select danganxuhao from TY_danganxuhao where xuehao in  
    (select quanxian from UserTable where name=@name)
    GO
    UserTable 表
    quanxian(varchar)    name(varchar)
    001,008               ty
    008,010                t
    TY_danganxuhao 表
    xuehao(char)   danganxuhao(varchar)
    001             adfsadf
    002             asdfasdf
    003             asdfasdf
      

  2.   

    好像是数据类型 的因素啊
    我只知道是
    where xuehao in  
    (select quanxian from UserTable where name=@name)  里的错误
      

  3.   

    二楼的意思是------楼主你写错了列名你写的:where xuhao in  
    (select quanxian from UserTable where name=@name)二楼写的:where xuehao in  
    (select quanxian from UserTable where name=@name)
    'xuhao'<>'xuehao'
      

  4.   

    create table UserTable
    (
       quanxian varchar(100),   
       name varchar (100)
    )create table TY_danganxuhao
    (
       xuehao char(10),   
       danganxuhao varchar (100)
    )
    insert UserTable select '001,008','ty'
    insert UserTable select '008,010','t'insert TY_danganxuhao select '001','adfsadf'
    insert TY_danganxuhao select '002','asdfasdf'
    insert TY_danganxuhao select '003','asdfasdf'select T.danganxuhao from TY_danganxuhao T,UserTable U 
    where 
    charindex(RTRIM(LTRIM(T.xuehao)),U.quanxian)>0 and U.name='ty'
      

  5.   

    CREATE   PROCEDURE SPty_list
    @name varchar(20)
     AS
    select T.danganxuhao from TY_danganxuhao T,UserTable U 
    where 
    charindex(RTRIM(LTRIM(T.xuehao)),U.quanxian)>0 and U.name=@name
    GO
      

  6.   


    2个表中quanxian列和xuehao列结构不一样所以无法用xuehao in (select quanxian .....这种查询条件达到目的
    改一下CREATE   PROCEDURE SPty_list
    @name varchar(20)
     AS
    select danganxuhao from TY_danganxuhao a where 
    exists(select * from UserTable where name=@name and 
    (left(quanxian,3)=a.xuehao or right(quanxian,3)=a.xuehao))
    GO
      

  7.   

    Top  
     scmail81 
     说的有道理 
    我就是想写一个xuehao in (001,002,003)的形式 
    但系统提示类型不一样
      

  8.   

    还是不行啊    select danganxuhao from TY_danganxuhao a where 
    exists(select * from UserTable where name=@name and 
    (left(quanxian,3)=a.xuehao or right(quanxian,3)=a.xuehao))a  是什么意思啊
      

  9.   

    UserTable 表
    quanxian(varchar)    name(varchar)
    001,008               ty
    008,010                t
    001,002,003,004,005,006    同样  //呢?(left(quanxian,3)=a.xuehao or right(quanxian,3)=a.xuehao)) 是什么意思?
      

  10.   

    谢谢
    scmail81
    能解释一下个个函数的意思么
    CREATE   PROCEDURE SPty_list
    @name varchar(20)
     AS
    select T.danganxuhao from TY_danganxuhao T,UserTable U 
    where 
    charindex(RTRIM(LTRIM(T.xuehao)),U.quanxian)>0 and U.name=@name
    GO