首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

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

2012-04-07 
关于SQL语句的一个问题怎样在存储过程里写一个SQL插入语句,判断同一个用户在一天内执行两次插入后不再执行

关于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

热点排行