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 |
|
and7ew
Starting Member
2 Posts |
Posted - 2009-06-23 : 15:04:42
|
| Hi all,Right now, I have the following tablesStudent TablestudentId(int) sName(nvarchar) sCourses(nvarchar)1000 Andrew Edwards 1000;10011001 Tommy Jones 1000CoursescourseId(int) courseName(nvarchar) 1000 Programming 1011001 System Design 101When I try to execute the following SELECT statement, I only get records with 1000 even though I specified it to get all fields with the '1000' in it... SELECT s.studentId, s.sName, s.eventFROM tblStudent s INNER JOIN tblCourses ON s.event = CAST(c.eventId AS nvarchar)WHERE (s.event LIKE '%1000%')What am I doing wrong? any ideas? |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2009-06-23 : 15:29:00
|
Is sCourse in your tables Event in your query? If so, how would 1000 ever equal 1000; 1001? This line will not let that happen ON s.event = CAST(c.eventId AS nvarchar)You could try something like:SELECT s.studentId, s.sName, s.eventFROM tblStudent s INNER JOIN tblCourses ON s.event LIKE '%' + CAST(c.eventId AS nvarchar) + '%' |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-06-23 : 15:47:10
|
ON ';' + s.event + ';' LIKE '%;' + CAST(c.eventId AS nvarchar(40)) + ';%' E 12°55'05.63"N 56°04'39.26" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
and7ew
Starting Member
2 Posts |
Posted - 2009-06-24 : 09:04:30
|
| Thanks Lamprey! That Query worked like a charm =)One question, right now with the query I get the following...Andrew Smith Programming 101Andrew Smith System Design 101Andrew Smith Ethics 102how do you combine the following records into one so its something like thisAndrew Smith Programming 101, System Design 101, Ethics 102 |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-06-24 : 09:06:50
|
quote: Originally posted by and7ew Thanks Lamprey! That Query worked like a charm =)
Not quite. See the difference when you have both "10" and "100" for ID.See post made 06/23/2009 : 15:47:10 to deal with those.See topic herehttp://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254how to concatenate strings. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|
|
|