Mending some SQL

Log in to stop seeing adverts
This page may contain links to companies such as eBay and Amazon. As an affiliate of these sites I may earn commission if you click the link and make a purchase

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

P Pld Pts
1Liverpool1639
2Chelsea1735
3Arsenal1733
4Nottm F1731
5Bournemouth1728
6Aston Villa1728
7Manchester C  1727
8Newcastle1726
9Fulham1725
10Brighton1725
11Tottenham 1723
12Brentford1723
13Manchester U1722
14West Ham1720
15Everton1616
16Palace1716
17Leicester1714
18Wolves1712
19Ipswich1712
20Southampton176

Latest posts

Back
Top