SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 iUpdate column wth variables from another column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Peter Horne
Starting Member

Australia
1 Posts

Posted - 11/19/2012 :  01:30:35  Show Profile  Reply with Quote
Hi all,
first post here, bear with me!
I have a table with fields of InspectionDate, Type & DueDate. I need to update DueDate field(automatically??)with different date values depending on the values in InspectDate & Type fields.

Eg InspectDate 1/1/2012, Type (A), DueDate would be (InspectDate+1)
InspectDate 1/1/2012, Type (B) , Duedate would be(InpsectDate+20)
Etc, etc.

Any help appreciated.

Thanks
Pete

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 11/19/2012 :  01:57:11  Show Profile  Reply with Quote
so are there are different rules for different type values? then you need to make DueDate a computed field based on rules using a CASE WHEN expression

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2168 Posts

Posted - 11/19/2012 :  02:11:44  Show Profile  Reply with Quote
Just this script is based on your information..


CREATE TABLE Test1 (InspectionDate date, [Type] char(1), 
DueDate AS case when InspectionDate = '1/1/2012' and [type] = 'A' THEN dateadd(DD, 1, InspectionDate)
				when InspectionDate = '1/1/2012' and [type] = 'B' THEN dateadd(DD, 20, InspectionDate)
				ELSE InspectionDate end  )
--I need to update DueDate field(automatically??)with different date values depending on the values in InspectDate & Type fields.
INSERT INTO Test1(InspectionDate, Type) VALUES ('1/1/2012', 'A'), ('1/1/2012', 'B')
GO
SELECT * FROM Test1
GO
DROP TABLE Test1


--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 11/19/2012 :  02:31:03  Show Profile  Reply with Quote
another way though not recommended is to create an INSERT,UPDATE trigger on table to do this computation

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000