两个小问题,关于批量删除,谢谢大家

people2009 2008-03-31 09:05:50
1.CREATE proc sp_Delfolk
@selecteds varchar(300)
AS
?这儿如何判断人员表是否使用,如果使用,返回-1,我用
IF EXISTS(Select * from hr_staff where staff_folk IN (@selecteds))为什么不正确
///////////////////////////////////////////////////////
2表chitty(单据表)
chitty_id chitty_ok(是否审核)
1 1
2 0
3 1
...
CREATE proc sp_Delchitty
@selecteds varchar(300)
AS
这儿如何判断chitty_id是否包含在@selecteds中,并是否已审核,如果是,返回-1
...全文
97 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
people2009 2008-03-31
  • 打赏
  • 举报
回复
谢谢大家
IF (Select count(1) from hr_staff where charindex(','+ staff_folk+',',','+@selecteds+',')>0)>0
set @use=-1
IF (Select count(1) from hr_PAY where charindex(','+ staff_folk+',',','+@selecteds+',')>0)>0
set @use=-1
两个应该怎么做
ojuju10 2008-03-31
  • 打赏
  • 举报
回复

2表chitty(单据表)
chitty_id chitty_ok(是否审核)
1 1
2 0
3 1
...
CREATE proc sp_Delchitty
@selecteds varchar(300)
AS
if exists(select 1 from chitty where chitty_id=@selecteds and chitty_oK)
begin

return -1
end


people2009 2008-03-31
  • 打赏
  • 举报
回复
谢谢大家,第二个问题是这样的.
首先判断chitty_id是否包含@selecteds中,如果是,还要判断是否已经已审核,如果已经审核,也不能删除,应该如何判断
wzy_love_sly 2008-03-31
  • 打赏
  • 举报
回复
列是int类型就

','+ltrim(列名)+','
people2009 2008-03-31
  • 打赏
  • 举报
回复
谢谢大家,但是还晃对,提示:256错误,数据类型charindex无效,充许的类型为....
wzy_love_sly 2008-03-31
  • 打赏
  • 举报
回复
CREATE proc sp_Delfolk
@selecteds varchar(300),
@use int output
AS
IF (Select count(1) from hr_staff where charindex(','+ staff_folk+',',','+@selecteds+',')>0)>0
set @use=-1
else
set @use=0
gahade 2008-03-31
  • 打赏
  • 举报
回复

IF EXISTS(Select * from hr_staff where charindex(','+staff_folk+',',','+@selecteds+',')>0)


下面那个也一样判断
dawugui 2008-03-31
  • 打赏
  • 举报
回复
第二个和第一个的问题一样.
dawugui 2008-03-31
  • 打赏
  • 举报
回复
@selecteds varchar(300)
其格式应该为:'''A'',''B'',''C''',不是'A,B,C'

declare @selecteds varchar(300)
set @selecteds = '''A'',''B'',''C'''

select @selecteds as '@selecteds'

/*
@selecteds
------------
'A','B','C'

(1 行受影响)
*/

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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