If else condition in stored procedure

Posted by Anishabathija under Sql Server on 5/13/2013 | Points: 10 | Views : 3766 | Status : [Member] | Replies : 1
Hi I have a condition as follows : where I am passing the parameters Name and ID to the SP
and I am extracting Name1 and ID1 from the table student.
Now if the name extracted is the same as name passed I want it to update.
Below is the code.
However I think its not functioning because I need to put a for loop and extract all names present and the compare it.
Please advice me on the approach, Any help will be greatly appreciated.


Select @Name1 = @Name from tbl_student
Select @id = @id from tbl_student

Set @id1 = substring(@id,7,1)
( @Name1 = @Name and @id1 = @id)

update dbo.tbl_student
set Name=@Name1,
Id =@Id1 where Id= ID1



Posted by: Niladri.Biswas on: 5/13/2013 [Member] Platinum | Points: 25

What is
Id= ID1 
? I mean ID1

That may be Id= @id...

any way as per teh code provided I believe that the culprit is

where Id= ID1

So check the condition again

Best Regards,
Niladri Biswas

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

Login to post response