Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update table

Status
Not open for further replies.

site

Programmer
Oct 23, 2001
44
AT
Hi, All,

How to write stored procedure to update table to create new field(DEADLINE) for expressing "DEADLINE" field running by each year?

example:
"DEADLINE" for this year is 12/31/01 after this that should be 12/31/02 so on.

Thank you very much for your kind help.
Jing
 

How about something like this?

Update tbl set deadline=dateadd(year,1,deadline)
Where <insert your criteria> Terry
Please review faq183-874.

&quot;The greatest obstacle to discovery is not ignorance -- it is the illusion of knowledge.&quot; - Daniel J Boorstin
 
Hi, tlbroadbent,

I think this doesn't work. because I just want to create new field like that. Right now I don't have &quot;DEADLINE&quot; field in this table. And also, the
&quot;dateadd(year,1,deadline)&quot; only return 'year' not for whole 'dd/mm/yy'. I want &quot;DEADLINE' field automatic running by last date of year.

welcome to any suggestion.
Thanks again.

Jing
 

[ol][li]dateadd(year,1,deadline) adds 1 year to the current value of the column named deadline. It doesn't return only the year. See date functions in SQL Books Online for more information about the dateadd function.
[li]I'm unsure of your question. Is the problem adding the column to the table or is the problem updating the column after it is added?

You can add a column to a SQL table with the following SQL script.

Alter Table Add Deadline datetime NULL

You can update the Deadline column in a stored procedure as in in the following T-SQL script.

Create Procedure UpdateDeadline As

Update tbl Set Deadline=<some value>
Where <some criteria>
[/ol]That is as much detail as I can give based on the info you provided. Terry Broadbent
Please review faq183-874.

&quot;The greatest obstacle to discovery is not ignorance -- it is the illusion of knowledge.&quot; - Daniel J Boorstin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top