如果日期是当前的,则更新,否则插入记录 [英] update if date is current else insert the record

查看:72
本文介绍了如果日期是当前的,则更新,否则插入记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我需要的是,如果我的表每天更新两次,而不是历史表更新一次,记录将更新
但是如果一天中我的表上的更新比历史表中的更新要插入一次,记录就会插入.

hi to all..

i need that if the updation on my table goes twice in a day than in historytable the record goes to update
but if the updation on my table in a day goes once than in history table the record goest insert.

推荐答案

本文可能会为您提供帮助.

http://blogs.msdn. com/b/miah/archive/2008/02/17/sql-if-exists-update-else-insert.aspx [
This article might help you.

http://blogs.msdn.com/b/miah/archive/2008/02/17/sql-if-exists-update-else-insert.aspx[^]


请参考一些类似的讨论:
如果存在记录,请更新其他插入 [如果存在更新..其他插入 [ ^ ]
SQL-如果存在,则更新其他插入内容 [ SQL存储过程-如果存在,则更新,否则插入. [
Please refer some similar discussions:
If Record Exists, Update Else Insert[^]
If Exists Update.. Else Insert[^]
SQL - IF Exists Update Else Insert[^]
SQL Stored Procedure - if exists Update else Insert.[^]


如果存在(选择" x''FROM HistoryTable,其中[date] = @ ModifiedDate和PrimaryKeyColumn = @ PrimaryKeyValue)
开始
更新HistoryTable设置[日期] = @ModifiedDate,其中PrimaryKeyColumn = @ PrimaryKeyValue
结束
其他
开始
插入HistoryTable ........
结束
IF EXISTS(SELECT ''x'' FROM HistoryTable where [date]=@ModifiedDate and PrimaryKeyColumn=@PrimaryKeyValue)
begin
update HistoryTable set [date]= @ModifiedDate where PrimaryKeyColumn=@PrimaryKeyValue
end
else
begin
insert into HistoryTable ........
end


这篇关于如果日期是当前的,则更新,否则插入记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆