ALTER proc [dbo].[procvote]
@voteTime varchar(20),
@voteMac varchar(20),
@pk_article varchar(20)
AS
BEGIN
declare @countArt int, @count int,@countVote int
--先检查是否有这个参赛记录
select @count=(count(*)) from tb1 where substring(pk_article,1,18)=@pk_article
--再检查是否投票记录已经开启!
select @countVote=(count(*)) from tb1 where substring(pk_article,1,18)=@pk_article and islock=1
--再检测今天是否有投票记录
select @countArt=(count(*)) from tb2 where pk_article=@pk_article and voteMac=@voteMac and substring(convert(varchar(20),voteTime,120),1,10)=substring(@voteTime,1,10)
if(@count <> 0)
begin
if(@countVote=0)
begin
if(@countArt = 0)
begin
insert into blogVote(voteTime,voteMac,pk_article) values(@voteTime,@voteMac,@pk_article)
update bloggame set count_blog=count_blog+1 where substring(pk_article,1,18)=@pk_article
return 0
end
else
begin
return 3
end
end
else
begin
return 4
end
end
else
begin
return 2
end
SET NOCOUNT ON; -- Insert statements for procedure here
END问题是这样的,我获得返回值的时候,只能获得2和0,就是没有这个记录,或者是投票成功,至于投票被锁定和已经投过票的返回记录都是投票成功...是不是我的存储过程条件嵌套有问题,还是declare定义的时候出了问题,请教高手
@voteTime varchar(20),
@voteMac varchar(20),
@pk_article varchar(20)
AS
BEGIN
declare @countArt int, @count int,@countVote int
--先检查是否有这个参赛记录
select @count=(count(*)) from tb1 where substring(pk_article,1,18)=@pk_article
--再检查是否投票记录已经开启!
select @countVote=(count(*)) from tb1 where substring(pk_article,1,18)=@pk_article and islock=1
--再检测今天是否有投票记录
select @countArt=(count(*)) from tb2 where pk_article=@pk_article and voteMac=@voteMac and substring(convert(varchar(20),voteTime,120),1,10)=substring(@voteTime,1,10)
if(@count <> 0)
begin
if(@countVote=0)
begin
if(@countArt = 0)
begin
insert into blogVote(voteTime,voteMac,pk_article) values(@voteTime,@voteMac,@pk_article)
update bloggame set count_blog=count_blog+1 where substring(pk_article,1,18)=@pk_article
return 0
end
else
begin
return 3
end
end
else
begin
return 4
end
end
else
begin
return 2
end
SET NOCOUNT ON; -- Insert statements for procedure here
END问题是这样的,我获得返回值的时候,只能获得2和0,就是没有这个记录,或者是投票成功,至于投票被锁定和已经投过票的返回记录都是投票成功...是不是我的存储过程条件嵌套有问题,还是declare定义的时候出了问题,请教高手
解决方案 »
- substring的一个问题
- SIMPLE SQL SELECT QUESTION !! HELP
- 修改过的表
- 留痕,怎么做
- 求助,sqlserver2005的829错误处理!
- 没有id属性,SQL Server怎么分页
- 如果查询这几段字符串不在某字段中?
- 如何限定查询后返回结果的个数?
- 请教一个问题
- 急!新手请教:有个价格信息表由3个字段组成名称(name),金额(price),日期(IssueTime),想得到一个由名称,year1总金额,year2...总金额组成的各年度总金额统计表,不知SQL语句该怎么写?
- 谁讲讲 not for replication 是什么意思?联机帮助看不明白
- 查询语句。。。。
@votetime varchar(20),
@votemac varchar(20),
@pk_article varchar(20)
as
begin
set nocount on; --调下顺序 declare @countArt int, @count int,@countVote int
--先检查是否有这个参赛记录
select @count=count(1)
from tb1
where left(pk_article,18)=@pk_article --再检查是否投票记录已经开启!
select @countVote=count(1)
from tb1
where left(pk_article,18)=@pk_article and islock=1 --再检测今天是否有投票记录
select @countArt=count(*)
from tb2
where pk_article=@pk_article and voteMac=@voteMac
and convert(varchar(10),voteTime,120)=left(@voteTime,10) if(@count <> 0)
if(@countVote=0)
if(@countArt = 0)
begin insert into blogVote(voteTime,voteMac,pk_article)
values(@voteTime,@voteMac,@pk_article) update bloggame
set count_blog=count_blog+1
where left(pk_article,18)=@pk_article return 0 end
else --@countArt <> 0
return 3
else --@countVote<>0
return 4
else --@count = 0
return 2
end 没发现什么问题..
@voteTime varchar(20),
@voteMac varchar(20),
@pk_article varchar(20)
AS
BEGIN --先检查是否有这个参赛记录
if not exists (select 1 from tb1 where substring(pk_article,1,18)=@pk_article)
return 2--再检查是否投票记录已经开启!
if exists (select 1 from tb1 where substring(pk_article,1,18)=@pk_article and islock=1)
return 4--再检测今天是否有投票记录
if exists (select 1 from tb2 where pk_article=@pk_article and voteMac=@voteMac and substring(convert(varchar(20),voteTime,120),1,10)=substring(@voteTime,1,10))
return 3
insert into blogVote(voteTime,voteMac,pk_article) values(@voteTime,@voteMac,@pk_article)
update bloggame set count_blog=count_blog+1 where substring(pk_article,1,18)=@pk_article
return 0 SET NOCOUNT ON; -- Insert statements for procedure here
END
declare
@voteTime varchar(20),
@voteMac varchar(20),
@pk_article varchar(20) set @voteTime = ..
set @voteMac = ..
set @pk_article = ..if exists (select 1 from tb2 where pk_article=@pk_article and voteMac=@voteMac and substring(convert(varchar(20),voteTime,120),1,10)=substring(@voteTime,1,10))
print 'A'
这段代码是否能够打印出"A"