日期:2014-05-19  浏览次数:20536 次

求sql?
create   table   tb_conf(
      UserID         varchar(20)         primary   key     not   null,
      IP                 varchar(20)         not   null,
      dates           datetime    
)
我想创建一个存储过程,
create   procedure     pro_tbconf
      @IP       varchar(20)
as
........

实现的功能就是先根据IP去表里查找UserID         ,,
  如果表中没有此Ip就插入新的一行。。

谢谢拉

------解决方案--------------------
create procedure pro_tbconf
@IP varchar(20)
as
if exists( select use_id from tb_conf where ip=@ip)

select use_id from tb_conf where ip=@ip
else
insert into................
------解决方案--------------------
create procedure pro_tbconf
@IP varchar(20)
as

if not exists (select * from tb_conf where ip=@ip)
insert into tb_conf(IP) select @ip
go
------解决方案--------------------
create procedure pro_tbconf
@IP varchar(20)
if not exists (select ip from tb_conf where ip = @ip)
insert into tb_conf(userid,ip,dates) values(....)
as

------解决方案--------------------
create procedure pro_tbconf
@IP varchar(20)
as
if not exists (select ip from tb_conf where ip = @ip)
insert into tb_conf(userid,ip,dates) values(....)
go

------解决方案--------------------
哈哈,终于沙发 ,不过我理解的和牛人们理解有点偏差...