小问题
表名:vote
表列:id smartcard votetime
ID号 用户名 投票时间
SELECT @temp=ISNULL(COUNT([id]),0) from vote where smartcard = @cardNo and ABS(DATEDIFF(d,votetime,GETDATE())) > = 1
if @temp > 0
begin
.....今天已经提交了。不能再提交
end
else
begin
......提交成功
end
帮我看看是怎么回事,不管怎么样都可以提交成功。谢谢了。
[解决办法]
create table vote(id int,smartcard varchar(10),votetime datetime)
insert into vote
select 1, 'sa ', '2007-04-16 '
declare @cardno varchar(10)
set @cardno= 'sa '
if exists(SELECT 1
from vote
where smartcard = @cardNo and ABS(DATEDIFF(d,votetime,GETDATE())) > = 1)
begin
print '今天已经提交了。不能再提交 '
end
else
begin
print '提交成功 '
end
--结果
今天已经提交了。不能再提交
[解决办法]
if exists(Select * from vote where smartcard = @cardNo and Datediff(day,votetime,GETDATE())=0 )
begin
.....今天已经提交了。不能再提交
end
else
begin
......提交成功
end
[解决办法]
if exists(select * from vote where smartcard = @cardNo and ABS(DATEDIFF(d,votetime,GETDATE())) =0 )
if @temp > 0
begin
.....今天已经提交了。不能再提交
end
else
begin
......提交成功
end
我觉得应该反过来
[解决办法]
楼主是不是 Where 语句不对,试试这个
-----------------------------------------
declare @t table (id int,smartcard varchar(10),votetime datetime)
declare @temp int
insert into @t
select 1, 'sa ', '2007-04-16 '
--select * from @t
SELECT @temp=ISNULL(COUNT([id]),0) from @t where smartcard = 'sa ' and ABS(DATEDIFF(d,votetime,GETDATE())) = 0
if @temp > 0
begin
print( '今天已经提交了。不能再提交 ')
end
else
begin
print( '提交成功 ')
end