May 5, 2009 at 1:11 pm
Sir,
I have a table called project, in this table i have 2 columns date(datetime) and project(text). Now I want to give restriction in such a way that if I give a certain date to upload the project, then after that date is over, noone can further input anything in the project column.
Hope I can make you understand my problem.
I don't know how to do this, please help me!
May 5, 2009 at 9:27 pm
Hi,
Your condition (ie the certain date to upload the project) with in the table column or in the separate table or thro parameters.
ARUN SAS
May 5, 2009 at 11:22 pm
The condition should be in another table column where only date will be provided.
May 6, 2009 at 2:19 am
Hi,
try this trigger
CREATE TRIGGER Main_TABLE_TRG
ON MAIN_TABLE
FOR INSERT
AS
BEGIN
declare
@date datetime,
@proj varchar(100)
select @date1 = date,@proj = project
FROM INSERTED
If not exists (select 1 from second_table
where proj = @proj
and getdate()/*or @date1*/ between valid_from and valid_to)
begin
RAISERROR ('Project updating/ inserting expiries', 16, 1)
return
end
END
MAIN_TABLE
(
date datetime,
project varchar(100)
)
second_table
(
proj varchar(100),
valid_from datetime,
valid_to datetime
)
ARUN SAS
May 6, 2009 at 7:05 am
Thanks for replying.
I'll check the T-SQL and reply you back soon.
Thanks again!
May 9, 2009 at 8:56 am
Sir,
In second_table, i inserted following data:
----------------------------
proj | valid_from | valid_to
----------------------------
ABCD 1/7/2009 7/7/2009
----------------------------
and in MAIN_TABLE:
--------------------
date | project
--------------------
5/7/2009 ABCD
7/7/2009 ABCD
8/7/2009 ABCD
--------------------
MAIN_TABLE taking the project on 8/7/2009 without giving the alert.
and am not understanding where is the problem in TRIGGER!
please help!
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply