• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 156
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

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