TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Naveen Kumar
NA
73
5.1k
How to write a procedure for updating a table .
Jul 22 2014 3:38 AM
I had a table like this
id int identitty(1,1)
productname varchar(20)
Status char(1) like this
IF(@ACTION='U')
BEGIN
IF EXISTS(SELECT P_ID FROM TBL_PRODUCTS WHERE P_ID=@P_ID)
BEGIN
set @exp=(select COUNT(*) from TBL_PRODUCTS where P_NAME=@P_NAME)
set @exp1=(select count(*) from tbl_products where p_id=@P_ID and p_name=@P_NAME)
if((@exp<=1)and (@exp1=1))
Begin
UPDATE TBL_PRODUCTS SET
P_NAME=@P_NAME,
P_TAG_LINE=@P_TAG_LINE,
P_WEB=@P_WEB,
P_ACTIVE=@P_ACTIVE
WHERE P_ID=@P_ID;
IF(@@ERROR=0)
BEGIN
SET @ERROR_ID=1
END
ELSE
BEGIN
SET @ERROR_ID=0
END
End
ELSE
BEGIN
SET @ERROR_ID=-2
END
END
ELSE
BEGIN
SET @ERROR_ID=-2
END
END
here i can able to Update a record if the id is same and name is same and i want to do
product name should not repeat twice in table..
Reply
Answers (
2
)
Formatting columns with a sql query
Relationship b/w login table and signup table i sql ?