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
Umeh Chukwudi
NA
2
1.4k
pin check/ verification on stored procedure
Jun 2 2016 11:47 AM
I am new to stored procedures, and i am trying to create a procedure<br /> to check pin validation, and also create count for amount of times a given PIN is used.<br /> the database values are;<br /> id;<br /> Pin_no;- these holds the PIN numbers.<br /> Reg_num; - These holds the registration number of the specified PIN user. <br /> P_Session; - these holds the school session PIN number was used. <br /> Program; - these holds the school program PIN number was used.<br /><div> Tries; - these holds the amount of times PIN has been used and if more than 3 times PIN row deletes.</div><div>i have designed this code as below . pls help ;</div><div> </div><div> <div class="dp-highlighter"><ol class="dp-sql" start="1"><li class="alt"><span><span class="keyword">CREATE</span><span> </span><span class="keyword">PROCEDURE</span><span> [dbo].PinValidation </span></span></li><li class=""><span> @Pin_no <span class="keyword">varchar</span><span>(24), </span></span></li><li class="alt"><span> @Reg_Num <span class="keyword">varchar</span><span>(24), </span></span></li><li class=""><span> @Session <span class="keyword">varchar</span><span>(50), </span></span></li><li class="alt"><span> @Tries <span class="keyword">INT</span><span>, </span></span></li><li class=""><span> @Program <span class="keyword">varchar</span><span>(50) </span></span></li><li class="alt"><span><span class="keyword">AS</span><span> </span></span></li><li class=""><span><span class="keyword">begin</span><span> </span></span></li><li class="alt"><span> <span class="keyword">SELECT</span><span> Pin_no </span><span class="keyword">FROM</span><span> PIN </span></span></li><li class=""><span> <span class="keyword">WHERE</span><span> Pin_no=@Pin_no </span></span></li><li class="alt"><span> if @Reg_Num <span class="keyword">is</span><span> </span><span class="op">not</span><span> </span><span class="op">Null</span><span> </span></span></li><li class=""><span> <span class="keyword">BEGIN</span><span> </span></span></li><li class="alt"><span> IF <span class="op">NOT</span><span> EXISTS (</span><span class="keyword">SELECT</span><span> Reg_Num </span><span class="keyword">FROM</span><span> PIN </span><span class="keyword">WHERE</span><span> Reg_Num=@Reg_Num </span><span class="op">and</span><span> Program=@Program </span><span class="op">and</span><span> P_Session=@Session) </span></span></li><li class=""><span> <span class="keyword">BEGIN</span><span> </span></span></li><li class="alt"><span> <span class="keyword">UPDATE</span><span> PIN </span></span></li><li class=""><span> <span class="keyword">SET</span><span> Tries= Tries+1 </span></span></li><li class="alt"><span> <span class="keyword">WHERE</span><span> Reg_Num=@Reg_Num</span><span class="comment">--incrases the value of tries by 1 each time pin is used</span><span> </span></span></li><li class=""><span> <span class="keyword">SELECT</span><span> @Tries[Tries] </span></span></li><li class="alt"><span> <span class="keyword">end</span><span> </span></span></li><li class=""><span> <span class="keyword">ELSE</span><span> </span></span></li><li class="alt"><span> <span class="keyword">UPDATE</span><span> PIN </span></span></li><li class=""><span> <span class="keyword">SET</span><span> Reg_num = @Reg_Num, P_Session=@Session, Tries=Tries+1, Program=@Program </span></span></li><li class="alt"><span> <span class="keyword">Where</span><span> Pin_no=@Pin_no </span><span class="comment">--Updates database pin value for used pin on first usage</span><span> </span></span></li><li class=""><span> <span class="keyword">end</span><span> </span></span></li><li class="alt"><span> <span class="keyword">end</span><span> </span></span></li><li class=""><span> If @Tries <span class="keyword">is</span><span> </span><span class="op">not</span><span> </span><span class="op">Null</span><span> </span></span></li><li class="alt"><span> <span class="keyword">BEGIN</span><span> </span></span></li><li class=""><span> if <span class="op">NOT</span><span> EXISTS (</span><span class="keyword">SELECT</span><span> Pin_no </span><span class="keyword">FROM</span><span> PIN </span><span class="keyword">WHERE</span><span> Pin_no=@Pin_no) </span></span></li><li class="alt"><span> <span class="keyword">BEGIN</span><span> </span></span></li><li class=""><span> <span class="keyword">DELETE</span><span> </span><span class="keyword">FROM</span><span> [PIN ] </span></span></li><li class="alt"><span> <span class="keyword">WHERE</span><span> (( [Tries] = 3))</span><span class="comment">--Check the Amount of times pin has been used if >3 delete entire pin row</span><span> </span></span></li><li class=""><span> <span class="keyword">end</span><span> </span></span></li><li class="alt"><span> <span class="keyword">end</span><span> </span></span></li><li class=""><span> <span class="keyword">ELSE</span><span> </span></span></li><li class="alt"><span> <span class="keyword">BEGIN</span><span> </span></span></li><li class=""><span> <span class="keyword">SELECT</span><span> -1 </span></span></li><li class="alt"><span> <span class="keyword">END</span><span> <br /></span></span></li></ol></div></div>
Reply
Answers (
0
)
Ambiguous column name 'Associate_ID'.
error while trying to connect the sql server.