Click here to Skip to main content
15,896,522 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Dear All,

Sorry preciously my question was wrong...

Can anyone please guide me with some solution. Right now I am adding som infomation in a table, lets say as Sampletb. I have some column like Time,Status in Sampletb.

My requirement is if I enter any record in the Sampletb with a date (for ex:27-dec-2013 23:00) in the time column.

On this particular date and time,status of the particular record should be changed to 1....

could this be possible...

Please help me with this...
Posted
Updated 26-Dec-13 0:44am
v3

Hi,

you can user trigger for that. See the below link it will show you how to use it.

http://www.sqlusa.com/bestpractices/triggerformissingdata/[^]

http://technet.microsoft.com/en-us/library/ms189799.aspx[^]

Triggers -- SQL Server[^]
 
Share this answer
 
Comments
[no name] 26-Dec-13 5:50am    
Thanks for the suggestion..I am working on it...
Use Triggers

Check this link:
Triggers -- SQL Server[^]
 
Share this answer
 
Comments
[no name] 26-Dec-13 5:50am    
Thanks for the suggestion.
I have done this by generating sqljobs whenever any records are inserted in to the table.

For Generating the Jobs dynamically we have some store procedures like sp_add_job by default.

I created a SP in which I am calling SP_ADD_JOB by giving the date and time as parameters..

so whenever I insert any date in the table it creates a job dynamically and takes the date i insert as parameters and triggers at that time...

Hope it helps some one who is facing the same issue.
 
Share this answer
 
If the status is set by the date, why not use a view to return the values and generate that column dynamically.
 
Share this answer
 
Comments
[no name] 26-Dec-13 5:50am    
Can you explain me in brief...Actually I am Inserting one recoed in a table with a particular date ..on that date Inserted the corresponding record status should be updated..
Christian Graus 26-Dec-13 18:05pm    
If the status depends solely on the date, then you don't need to store a status, you can create a view using a CASE statement to create the status on the fly, and thus to always make it up to date without requiring a trigger. It may be more efficient to store the status, your milage may vary. It's just another option.
I have done this by generating dynamic sql jobs in a store procedure whenever any records gets submitted..
 
Share this answer
 
Comments
CHill60 3-Jan-14 15:43pm    
Really? Either a trigger to update the database, or define the status via a view would have been a better approach - see the other solutions

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900