当前位置: 代码迷 >> ASP.NET >> 关于SQL语句的一个有关问题
  详细解决方案

关于SQL语句的一个有关问题

热度:4360   发布时间:2013-02-25 00:00:00.0
关于SQL语句的一个问题
怎样在存储过程里写一个SQL插入语句,判断同一个用户在一天内执行两次插入后不再执行第三次?
字段名有username和datetime

------解决方案--------------------------------------------------------
用函数返回该用户今天发布信息的条数 小于2 就执行这条插入语句 


if(function(select count(*) from User where username= name and datetime = date())< 2)
 insert into User ....

乱写的是这个意思
------解决方案--------------------------------------------------------
SQL code
create proc ProcNameas    declare @count int    select count(*) from TableName where username = '' and datediff(day,biday,getdate())=0     if(@count <= 2)    begin        insert into .....//插入语句    endgo
------解决方案--------------------------------------------------------
探讨
SQL code
create proc ProcName
as
declare @count int
select count(*) from TableName where username = '' and datediff(day,biday,getdate())=0

if(@count <= 2)
begin
insert into .....//插入语句
end
go




试试吧!

------解决方案--------------------------------------------------------
create proc ProcName
@UserID varchar(20)=''
as
declare @count int
select count(*) from TableName where username =@UserID and datediff(day,biday,getdate())=0 

if(@count <= 2)
begin
insert into .....//插入语句
end
go
  相关解决方案