• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 153
  • Last Modified:

how can I write a sp to copy the new entered data to a colum with the if-else statement?

I have a store procedure need to do:
if column [projected_dop]<> column [cal_projected_dop]
then  
set column [new_dop]=[projected_dop]

The prupose is any new data entered by the user at the day time need to be copy to a column [new_cop]

My questions is how to right a store procedure like this ?
if worte it , see attachement, but have error:

how can I write a sp to copy the new entered data to a colum with the if-else statement?
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[dbo.tbl_vacancy_database_New_POD] 
	-- Add the parameters for the stored procedure here
 	
AS

if dbo.tbl_Vacancy_Database.[Projected_DOP]<> dbo.tbl_Vacancy_Database.[cal_Projected_DOP]
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

UPDATE dbo.tbl_Vacancy_Database 
SET New_DOP= dbo.tbl_Vacancy_Database.[Projected_DOP]
Exec [dbo].[tbl_vacancy_database_Insert_Records]
UPDATE dbo.tbl_Vacancy_Database  
SET Projected_DOP = dbo.tbl_Vacancy_Database.[New_DOP] WHERE dbo.tbl_Vacancy_Database.[New_DOP]IS NOT NULL

END
else 

BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

--UPDATE dbo.tbl_Vacancy_Database 
--SET New_DOP= dbo.tbl_Vacancy_Database.[Projected_DOP]
Exec [dbo].[tbl_vacancy_database_Insert_Records]
--UPDATE dbo.tbl_Vacancy_Database  
--SET Projected_DOP = dbo.tbl_Vacancy_Database.[New_DOP] WHERE dbo.tbl_Vacancy_Database.[New_DOP]IS NOT NULL

END

Open in new window

0
FinghtingMiao
Asked:
FinghtingMiao
1 Solution
 
HainKurtSr. System AnalystCommented:
try:

update mytable
set [new_dop]=[projected_dop]
where [projected_dop]<>[cal_projected_dop]
0
 
FinghtingMiaoAuthor Commented:
Thank you
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now