plainwrapname
asked on
If row exists in table update else insert a new row
I have the following stored procedure:
USE [DATABASE]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[InsertNewRow]
@StartDate DateTime = null
AS
if @StartDate is null
set @StartDate = getdate()
Begin
Insert [dbo].[TempPortfolioHistor y]
EXEC CITYCRM_MSCRM.dbo.Portfoli oHistory @EndDate = @StartDate
End
It adds a new row to the table.
Now the SP is going to be run more than once a day so I need to update the row if there is a row with the same date (first column in the row of the table), otherwise I need to do what the SP does currently.
Any help would be appreciated.
USE [DATABASE]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[InsertNewRow]
@StartDate DateTime = null
AS
if @StartDate is null
set @StartDate = getdate()
Begin
Insert [dbo].[TempPortfolioHistor
EXEC CITYCRM_MSCRM.dbo.Portfoli
End
It adds a new row to the table.
Now the SP is going to be run more than once a day so I need to update the row if there is a row with the same date (first column in the row of the table), otherwise I need to do what the SP does currently.
Any help would be appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER