存储过程,多条件删除

tjbus2008 2009-05-15 02:50:51
Create Proc Proc_DeleteBaseData1(
@txtone varchar(50),
@txttwo varchar(50),
@txtcontion varchar(50),
@outprint varchar(50) output)
as
begin
if @txtcontion='全部'
delete from 基础数据 where 日期 between @txtone and @txttwo
else
delete from 基础数据 where 车队 in (@txtcontion) and 日期 between @txtone and @txttwo
END
SET @outprint='删除成功'
影响行数为0
其中@txtcontion有可能是选择的多个车队,1车队,2车队,3车队,或者只是一个车队,例如1车队.
不知道如何解决,谢谢
...全文
145 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
-狙击手- 2009-05-15
  • 打赏
  • 举报
回复
你select 一下看看有没有结果,说不定本身就没有记录满足
看看是不是有空格
--try

Create Proc Proc_DeleteBaseData1( 
@txtone varchar(50),
@txttwo varchar(50),
@txtcontion varchar(50),
@outprint varchar(50) output)
as
begin
if @txtcontion='全部'
delete from 基础数据 where 日期 between @txtone and @txttwo
else
delete from 基础数据 where charindex(','+ltrim(rtrim(车队))+',',','+@txtcontion+',')>0 and 日期 between @txtone and @txttwo
END
SET @outprint='删除成功'
tjbus2008 2009-05-15
  • 打赏
  • 举报
回复
exec proc_deletebasedata1 '878车队','2009-04-01','2009-04-01','删除成功'
返回的是影响行数0
无心雨云 2009-05-15
  • 打赏
  • 举报
回复
学了
SQL77 2009-05-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 happyflystone 的回复:]
SQL codeCreate Proc Proc_DeleteBaseData1(
@txtone varchar(50),
@txttwo varchar(50),
@txtcontion varchar(50),
@outprint varchar(50) output)
as
begin
if @txtcontion='全部'
delete from 基础数据 where 日期 between @txtone and @txttwo
else
delete from 基础数据 where charindex(','+车队+',',','+@txtcontion+',')>0 and 日期 between @txtone and @txttwo
END
SET @outprint='删除成功'
[/Quote]

速度啊!!!真快!!!
-狙击手- 2009-05-15
  • 打赏
  • 举报
回复
Create Proc Proc_DeleteBaseData1( 
@txtone varchar(50),
@txttwo varchar(50),
@txtcontion varchar(50),
@outprint varchar(50) output)
as
begin
if @txtcontion='全部'
delete from 基础数据 where 日期 between @txtone and @txttwo
else
delete from 基础数据 where charindex(','+车队+',',','+@txtcontion+',')>0 and 日期 between @txtone and @txttwo
END
SET @outprint='删除成功'
-狙击手- 2009-05-15
  • 打赏
  • 举报
回复
Create Proc Proc_DeleteBaseData1( 
@txtone varchar(50),
@txttwo varchar(50),
@txtcontion varchar(50),
@outprint varchar(50) output)
as
begin
if @txtcontion='全部'
delete from 基础数据 where 日期 between @txtone and @txttwo
else
delete from 基础数据 where charindex(','+车队+',',','+@txtcontion+',')>0 and 日期 between @txtone and @txttwo
END
SET @outprint='删除成功'

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧