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
怎么不好使啊
@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
怎么不好使啊
@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
我只知道是
where xuehao in
(select quanxian from UserTable where name=@name) 里的错误
(select quanxian from UserTable where name=@name)二楼写的:where xuehao in
(select quanxian from UserTable where name=@name)
'xuhao'<>'xuehao'
(
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'
@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
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
scmail81
说的有道理
我就是想写一个xuehao in (001,002,003)的形式
但系统提示类型不一样
exists(select * from UserTable where name=@name and
(left(quanxian,3)=a.xuehao or right(quanxian,3)=a.xuehao))a 是什么意思啊
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)) 是什么意思?
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