Click here to Skip to main content
15,887,262 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
In my database I have 3 columns ie., Id,Name,Subject(Marks).I inserted records as 1,Sai, 20.
When I am trying to insert new marks to the Sai ,it won't accept new marks to the Sai.
That means I want to restrict to re-enter the marks for particular record and it allows only one time to enter marks..
Can you please tell me How to write code for this.. ??
Posted
Comments
Thanks7872 8-Jul-15 9:10am    
In very simple terms (as per as the question is concerned) ,One time means insert and multiple times means update. Allow insert only. Restrict the update. What is the problem?

1 solution

Before commiting the INSERT/UPDATE statement you need to check if the Marks column has data or not.
Try something like-
SQL
IF(NOT EXISTS(SELECT Marks FROM YourTable WHERE Id=@Id AND Marks IS NOT NULL))
BEGIN
   -- Your INSERT/UPDATE query goes here
   -- SELECT 'Success' AS Message
END
--ELSE
--BEGIN
     --SELECT 'Failure' AS Message
--END


Hope, it helps :)
Please let me know if you need further help.
 
Share this answer
 
v3
Comments
Kanaparthi Sureshma Reddy 8-Jul-15 4:54am    
Actually the column has the data(20) but If I try to change that data(20 to 25) it won't allow me to enter new data(25)..
For that how to restrict to enter new data(the marks always should be what I insert first time only ie., 20 only)..
Suvendu Shekhar Giri 8-Jul-15 4:58am    
The above solution should still works. Doesn't it?
Kanaparthi Sureshma Reddy 8-Jul-15 5:17am    
Can you please write including with the insert Stored procedure...Here Id is the primary key
Kanaparthi Sureshma Reddy 8-Jul-15 5:08am    
It's not Working..

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