Here is the code.

Set con1 = CreateObject("adodb.connection")
Set rs3 = CreateObject("adodb.recordset")
con1.Open "Provider=sqloledb;Data Source=xxx;Initial Catalog=yyy; User Id=sa; Password=@1234;"

rs3.Open "select a.courseid,a.semester,a.period,c.Category,b.credit,a.gradecode,d.GradePoint from x a ,y b,z c,m d where a.rollno='" & pprollno & "' and a.semester<>'" & prsem & "' and a.period<>'" & pperiod & "' and a.categoryid=c.categoryid and a.courseid=b.courseid and a.gradecode=d.gradecode order by a.semester,a.period", con1
If Not (rs3.BOF And rs3.EOF) Then
Do While Not rs3.EOF
pcrseid = rs3("courseid")
psemester = rs3("semester")
vperiod = rs3("period")
mcategory = Trim(rs3("category"))
mcredit = rs3("credit")
mgrade = rs3("gradecode")
mgradepoint = rs3("gradepoint")
End If

Am getting wrong values from the record set. Am don't know.Why ?Please help me out.

Without knowing more about your data, and the datatypes of the columns, and what you're expecting to get, this is impossible to answer.

However, you could look at some things that might point you in the right direction.
1. Are the datatypes correctly matching the datatypes of you selection criteria variables? (e.g. if column a.period is an integer, you should not enclose it in single quotes)
2. Are there extra characters in your strings? (e.g. 'Joe ' vs. 'Joe'...you could use the 'trim' function on the variable values)

If that doesn't help, you might consider just copying the SQL statement to SSMS, plug in some sample values and see if it runs there. If not, fix it so that it does, the re-apply your changes to your VBA version.

Good luck! Hope this helps!

so are the wrong records being selected or is it the correct records and the wrong data in the record