Mending some SQL

Log in to stop seeing adverts

Status
Not open for further replies.
I haven't got access mate. That code produced an error (see below):

Code:
SELECT 
Course.[ID], 
Course.Title, 
Course.Outline, 
Course.CPD, 
Course.Presenter, 
Course.Timings, 
Course.Compulsory, 
CourseEvent.CourseLocation, 
CourseEvent.CourseDate, 
CourseEvent.CourseTime
FROM 
(((((((Course RIGHT JOIN CourseEvent ON Course.[ID] = CourseEvent.CourseID) 
LEFT JOIN GroupCourse ON Course.[ID] = GroupCourse.CourseID) 
LEFT JOIN [Group] ON GroupCourse.GroupID = Group.[ID]) 
LEFT JOIN PQE ON Course.PQEID = PQE.[ID]) 
LEFT JOIN ResponsibilityCourse ON Course.[ID] = ResponsibilityCourse.CourseID) 
LEFT JOIN Responsibility ON ResponsibilityCourse.ResponsibilityID = Responsibility.ID) 
LEFT JOIN Location ON CourseEvent.CourseLocation = Location.[ID]) 
LEFT JOIN RoleCourse ON Course.ID = RoleCourse.CourseID)

Server: Msg 156, Level 15, State 1, Line 17
Incorrect syntax near the keyword 'Group'.

[Group] - Remove those brackets.
 
[Group] - Remove those brackets.

group is a key word and it'll need the brackets to know it's a table and not you trying to group thing

:102:
 
LEFT JOIN [Group] ON GroupCourse.GroupID = [Group].[ID])

try square brackets around the second group
 
That sorted it, thanks.

Now the problem is getting all the data I require back:

Code:
SELECT
Course.ID 			
Course.Title 			
Course.Outline 			
PQE.Description 	
PQE.ID 			
Course.Presenter		
Course.Timings			
Course.Compulsory 	
Course.CPD 		
CourseType.Description 	
CourseType.ID 		
CourseEvent.ID 			
CourseEvent.CourseLocation 
Location.Description 		
Responsibility.Description 	
Responsibility.ID 					
CourseEvent.CourseGroup 	
CourseEvent.CourseDate 		
CourseEvent.CourseTime 		
Role.Description 	
Role.ID 		
DelegateType.[Delegate Type] 	
DelegateType.ID 		
[Group].ID 		
[Group].Description

There seems to be a problem with the Role and the DelegateType tables.

I get the following error:

Server: Msg 107, Level 16, State 3, Line 1
The column prefix 'Role' does not match with a table name or alias name used in the query.
 
That sorted it, thanks.
I get the following error:

Server: Msg 107, Level 16, State 3, Line 1
The column prefix 'Role' does not match with a table name or alias name used in the query.

hold on, my bad, i think i forgot to include it
 
Last edited:
Code:
SELECT CourseEvent.*
FROM (((((((((Course RIGHT JOIN CourseEvent ON Course.ID = CourseEvent.CourseID) LEFT JOIN GroupCourse ON Course.ID = GroupCourse.CourseID) LEFT JOIN [Group] ON GroupCourse.GroupID = Group.ID) LEFT JOIN PQE ON Course.PQEID = PQE.ID) LEFT JOIN ResponsibilityCourse ON Course.ID = ResponsibilityCourse.CourseID) LEFT JOIN Responsibility ON ResponsibilityCourse.ResponsibilityID = Responsibility.ID) LEFT JOIN Location ON CourseEvent.CourseLocation = Location.ID) LEFT JOIN RoleCourse ON Course.ID = RoleCourse.CourseID) LEFT JOIN Role ON RoleCourse.RoleID = Role.ID) LEFT JOIN DelegateType ON Course.DelegateTypeID = DelegateType.ID;

use that bit for your joins and select whatever you like

you'll need to correct the [group] thing again (a translation from jet sql to t-sql anomaly i think)
 
Last edited:
group is a key word and it'll need the brackets to know it's a table and not you trying to group thing

:102:

Group is a keyword. :icon_redf :icon_redf :icon_redf Who would name a table the same as a keyword? :102:
 
Group is a keyword. :icon_redf :icon_redf :icon_redf Who would name a table the same as a keyword? :102:

yes that is a bit daft

at least it isn't called "table1"
 
It wasn't me - it's an old application that I am in the process of replacing but I need all the raw data that this stored procedure extracts.
 
Ok, this is doing my head in now.

Who can advise on this:

If a field in a table called location has multiple values, say the location field has "leicester, derby" and that table is related to another table called course, when trying to get the course back, how do I stop it from producing the following result for each occurence where there is multiple values:
Code:
course      location
football    leicester  
football    derby
tennis      leicester
tennis      derby

I just want:

Code:
course      location
football    leicester, derby  
tennis      leicester, derby
 
Ok, this is doing my head in now.

Who can advise on this:

If a field in a table called location has multiple values, say the location field has "leicester, derby" and that table is related to another table called course, when trying to get the course back, how do I stop it from producing the following result for each occurence where there is multiple values:
Code:
course      location
football    leicester  
football    derby
tennis      leicester
tennis      derby

I just want:

Code:
course      location
football    leicester, derby  
tennis      leicester, derby


get to grips with cross tab queries...then i'll tell you how to turn that into what you want...
 
I have got to grips with it but just need to get multiple values in some of the fields.
 
I have got to grips with it but just need to get multiple values in some of the fields.

after the cross tab, write a new field, something like:-

LocationMultiple:iif([Leicester]>0,"Leicester ","") & iif([Derby]>0,"Derby ","") & iif([Coventry]>0,"Coventry ","")
 
Status
Not open for further replies.
Log in to stop seeing adverts

Championship

P Pld Pts
1Leicester4697
2Ipswich4696
3Leeds Utd4690
4Southampton4687
5West Brom4675
6Norwich City4673
7Hull City4670
8Middlesbro4669
9Coventry City4664
10Preston 4663
11Bristol City4662
12Cardiff City4662
13Millwall4659
14Swansea City4657
15Watford4656
16Sunderland4656
17Stoke City4656
18QPR4656
19Blackburn 4653
20Sheffield W4653
21Plymouth 4651
22Birmingham4650
23Huddersfield4645
24Rotherham Utd4627

Latest posts

Top