Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
Hi,

I want to fetch data from three table of database in which i am getting exception,query which i am using is
SQL
select StudentInfoId, RegistrationNo,FirstName,MiddleName,LastName,FathersName,MothersName,DateOfBirth,CurrentClassNo,SectionNo,RollNO,Status,MobileNo,CAddress1,CCity,CZipCode,PAddress2,PCity,PZipCode,FathersOccupation,HouseAllocated,Medium.MediumName,SubjectName,Height,Weight,IdMarks1 from StudentInfo,Medium,Subjects where RegistrationNo='1' and Medium.MediumId=StudentInfo.Medium and StudentInfo.Subjects=Subjects.SubjectId 

The Exception is "Conversion failed when converting the varchar value |2|3| to data type smallint". where |2|3| is the data in the field of StudentInfo.Subjects.
Here StudentInfo.Subjects is of type varchar and Subjects.SubjectId is of type smallint.

Pls suggest me a way to do same.

Thanks
Abhishek
Posted
Updated 13-Jun-11 1:55am
v3

The query failure shows a flaw in your data definition: the field 'Subjects' is actually a set (of smallints) and should find place into a separate table. For instance, assuming StudentInfoId is a primary key, you should have

StudententInfoIdSubject
1002
1003


to represent the subjects 2,3 for the student having id=100.
 
Share this answer
 
v4
Comments
abhiamity86 16-Jun-11 2:46am    
Thank for reply,
Exactely but how to do it pls suggest me.
CPallini 16-Jun-11 3:03am    
I already suggested you what to do: move the {StudentInfoId, Subject} link to another table (we call it normalization). Please read a database tutorial if this technique doesn't look clear to you.
better to use join query.....
for more details on join query see the below link
Link1[^]
Link2[^]
 
Share this answer
 

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