Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2011-03-22 : 03:21:56
|
| Hi all, I need to select a field by passing the idMy table (courses) is like this Courseid coursename 1 School 2 Engg 3 ArtsAnd my second table is like this Table (Exam)Examname cousreidAnnual 3,2Half_yearly 3,1,2Passing the courseid in table exam i need to get the coursename from courses table I need Output like thisexamname coursenameAnnual ArtsAnnual EnggHalf_yearly ArtsHalf_yearly EnggHalf_yearly School |
|
|
ahmeds08
Aged Yak Warrior
737 Posts |
Posted - 2011-03-22 : 03:33:44
|
| SELECT E.EXAMNAME,C.COURSENAME FROM EXAMS EINNER JOIN COURSES CON C.COURSEID=E.COURSEIDWHERE E.COURSEID=1 |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2011-03-22 : 03:46:01
|
| Thnx for your reply.. I tried this SELECT E.EXAMNAME,C.COURSENAME FROM EXAMS EINNER JOIN COURSES CON CONVERT(VARCHAR,C.CourseID)=E.CourseIDWHERE E.CourseID=1But i am getting this errorMsg 245, Level 16, State 1, Line 2Conversion failed when converting the varchar value '3,2' to data type int. |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2011-03-22 : 03:55:02
|
| And the exam table has the courseid like this 2,3,1 So it throws this error |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-03-22 : 04:00:43
|
| SELECT E.EXAMNAME,C.COURSENAME FROM EXAMS EINNER JOIN COURSES CON ','+E.COURSEID+',' like '%,'+cast(C.COURSEID as varchar(10))+',%'WHERE ','+E.COURSEID+',' like ',1,'MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|