• 全部
  • 基础类
  • 应用实例
  • 新技术前沿

sql模糊查询条件问题

hgqxz 2008-01-15 12:31:42
我要按 Name ,TANO ,Fdate ,Edate做模糊查询
请问这个where怎么写啊.我写的老是查不出我想要的结果
下面上是我写的存储过程
CREATE Procedure Plant_FIN_TA_GetViewByTANO(
@TANO nvarchar(50),
@User nvarchar(50),
@Fdate nvarchar(50),
@Edate nvarchar(50)
)
as
select AppDate, Name,Data,User,Status,TANO,Department,Amount from worklist
where
Name like '%'+@User+'%'
or TANO like '%'+@TANO +'%'
and (AppDate>=@Fdate and AppDate<=@Edate)
...全文
58 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
pt1314917 2008-01-15

CREATE Procedure Plant_FIN_TA_GetViewByTANO
@TANO nvarchar(50),
@User nvarchar(50),
@Fdate nvarchar(50),
@Edate nvarchar(50)
as
exec('select AppDate,Name,Data,User,Status,TANO,Department,Amount from worklist
where (Name like ''%'+@User+'%'' or TANO like ''%'+ @TANO + '%'')
and AppDate between '+ @Fdate +' and '+ @Edate)
回复
tim_spac 2008-01-15
增加Null容错
CREATE Procedure Plant_FIN_TA_GetViewByTANO ( 
@TANO nvarchar(50)
,@User nvarchar(50)
,@Fdate nvarchar(50)
,@Edate nvarchar(50)
) as
select
AppDate
,Name
,Data
,User
,Status
,TANO
,Department
,Amount
from worklist
where 1=1
and (isnull(@User,'') = '' or Name like '%'+@User+'%')
and (isnull(@TANO,'') = '' or TANO like '%'+@TANO+'%')
and (isnull(@Fdate,'') = '' or AppDate >= @Fdate)
and (isnull(@Edate,'') = '' or AppDate <= @Edate)
回复
-狙击手- 2008-01-15
CREATE         Procedure   Plant_FIN_TA_GetViewByTANO( 
@TANO nvarchar(50),
@User nvarchar(50),
@Fdate nvarchar(50),
@Edate nvarchar(50)
)
as
exec('select AppDate, Name,Data,User,Status,TANO,Department,Amount from worklist
where
Name like ''%'+@User+'%''
or TANO like ''%'+@TANO +'%''
and AppDate between '''+@Fdate +''' and '''+ @Edate+'''')

go
回复
tim_spac 2008-01-15
CREATE Procedure Plant_FIN_TA_GetViewByTANO(
@TANO nvarchar(50),
@User nvarchar(50),
@Fdate nvarchar(50),
@Edate nvarchar(50)
)
as
select
AppDate
,Name
,Data
,User
,Status
,TANO
,Department
,Amount
from worklist
where 1=1
and (@User = '' or Name like '%'+@User+'%')
and (@TANO = '' or TANO like '%'+@TANO+'%')
and (@Fdate = '' or AppDate >= @Fdate)
and (@Edate = '' or AppDate <= @Edate)

回复
-狙击手- 2008-01-15
CREATE         Procedure   Plant_FIN_TA_GetViewByTANO( 
@TANO nvarchar(50),
@User nvarchar(50),
@Fdate nvarchar(50),
@Edate nvarchar(50)
)
as
exec('select AppDate, Name,Data,User,Status,TANO,Department,Amount from worklist
where
Name like ''%'''+@User+'''%''
or TANO like ''%'''+@TANO +'''%''
and AppDate between '''+@Fdate +''' and '''+ @Edate+'''')
回复
相关推荐
发帖
MS-SQL Server
创建于2007-09-28

3.3w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2008-01-15 12:31
社区公告
暂无公告