For Loop in Stored Procedure in SQL Server 2005 [Resolved]

Posted by Anu_dgr8 under Sql Server on 6/28/2010 | Views : 14577 | Status : [Member] | Replies : 3
I Have a procedure to which i am passin a parameter.and i have table which has the values to that parameter..now i need to check whether the passed value to the strored procedure is present in that table..if its not present in the table,i want to make its entry into that table,otherwise its not inserted in that table.can somebody help me?

Thanku In Advance

Thanks and Regards,
Hoosha Boosha



Responses

Posted by: Vuyiswamb on: 6/28/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down

Resolved
Good Day Anu_dgr8

You need something like this


Create Proc usp_ChangeValue
(
@MyPar varchar(10)
)
as


DECLARE @Existance = (SELECT COUNT(*) FROM MYVALUTABLE WHERE VALUEFIELD = @MyPar )

IF (@Existance > 0)
BEGIN
--DONT INSERT INTO THE TABLE, BECAUSE THE VALUE EXIST
END
ELSE
BEGIN
--DO THE INSERT HERE
INSERT INTO MYVALUTABLE
VALUES (@MyPar,OTHERVALUES)
END


Thank you for posting at dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Anu_dgr8, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Anu_dgr8 on: 6/28/2010 [Member] Starter

Up
0
Down
Hey Thanks!I was able to figure out on my owm!

Thanks and Regards,
Hoosha Boosha

Anu_dgr8, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 6/28/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
lol :) Wonderful. I am glad you did it. Congradulation. Can you please mark you post as answered

thank you for posting at Dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Anu_dgr8, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response