Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Student_ID First Name Birthdate Gender class CorRes StuRes Newcol_compare
1 Butler 4-10-91 M 1 ABCD DCCD DC**


Hi above is my Table I want a query or procedure where i could compare StuRes and CorRes and then Keep the result in another Column called Newcol_compare where if they are equal then place * in Newcol_compare and if wrong input then show wrong input as it is.. can any one please help me with queryor procedure i am very new to SQL PLease help..???
Posted
Comments
choudhary.sumit 7-Dec-12 6:05am    
what equality u r comparing.as far as i understood, ABCD & DCCD has D& C equal.. if i m right and i will produce a query for u. otherwise elaborate your problem further.
syedmas 7-Dec-12 7:54am    
Thank you sir for your reply. but Over here the wrong answer should be displayed as it is and correct answer should be replaced with *. EXample is : DC** and i want to execute the statement for about some 10 or 20 row how will i do it.. if you could help it my help me in understanding SQL a little more. thank you..sir

1 solution

use this-

SQL
Select Newcol_compare= CASE WHEN  CorRes=StuRes THEN '*'  ELSE Newcol_compare END From Table_Name


mark as answer if helps, otherwise, let me know the problem i will explain again..
 
Share this answer
 
Comments
syedmas 8-Dec-12 0:40am    
Thank you sir for your reply. but Over here the wrong answer should be displayed as it is and correct answer should be replaced with *. EXample is : DC** and i want to execute the statement for about some 10 or 20 row how will i do it.. if you could help it my help me in understanding SQL a little more. thank you..sir
AnkitGoel.com 8-Dec-12 3:20am    
i think this query will satisfy your requirement.

may be i am not getting you please explain what is the problem in this query and what result you want.
syedmas 8-Dec-12 6:57am    
NO sir it didnt work for me. Example If in 1st column ABCD is correct answer and in 2nd Column student answer's as CBCA then i want to compare both the column and write result in 3rd column where answer should be like C**A. that is correct answers should become * and wrong answer should remain as it is. so can u please help thank you
AnkitGoel.com 8-Dec-12 7:05am    
How many letters are possible in CorRes and StuRes? is there any maximum length of data in these columns? if there is not any fixed length you may need to write a function.

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