473,395 Members | 1,756 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Query problem

MrMancunian
569 Expert 512MB
Hi,

I'm using the following query to (duh!) query my database. Now, I changed from Access 2003 to SQL Server 2005. It returns two errors and I can't find out why it does that.

The errors are:
Msg 195, Level 15, State 10, Line 1
'FIRST' is not a recognized built-in function name.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'tblAanvraag'.


Here's my query:

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT [tblAanvraag.AanvraagID] AS Aanvraagnummer, [tblAanvraag.PA-Nummer] AS [PA-Nummer], ([tblMedewerker.MedewerkerAchternaam]+', '+[tblMedewerker.MedewerkerVoornaam]+' '+[tblMedewerker.MedewerkerTussenvoegsel]) AS Aanvrager, [tblAanvraag.Aanvraagdatum] AS Aanvraagdatum, FIRST(tblMoleculair.MoleculairKorteNaam) AS Vraagstelling, [tblStatus.Status] AS Status FROM ((tblAanvraag INNER JOIN tblMedewerker ON tblAanvraag.AanvragerID = tblMedewerker.MedewerkerID) INNER JOIN tblStatus ON tblAanvraag.StatusCode = tblStatus.StatusCode) INNER JOIN (tblAangevraagdMoleculair INNER JOIN tblMoleculair ON tblAangevraagdMoleculair.MoleculairID = tblMoleculair.MoleculairID) ON tblAanvraag.AanvraagID = tblAangevraagdMoleculair.AanvraagID GROUP BY [tblAanvraag.AanvraagID], [tblAanvraag.PA-Nummer], ([tblMedewerker.MedewerkerAchternaam]+', '+[tblMedewerker.MedewerkerVoornaam]+' '+[tblMedewerker.MedewerkerTussenvoegsel]), [tblAanvraag.Aanvraagdatum], [tblStatus.Status], tblAanvraag.MoleculairePathologie, tblAanvraag.StatusCode HAVING (((tblAanvraag.MoleculairePathologie)=True) AND ((tblAanvraag.StatusCode)<4))
Can anyone help me with this one? It would be greatly appeciated!

Cheers,

Steven
Jul 29 '08 #1
7 1065
r035198x
13,262 8TB
The part

Expand|Select|Wrap|Line Numbers
  1.  INNER JOIN (tblAangevraagdMoleculair 
  2.           INNER JOIN tblMoleculair ON tblAangevraagdMoleculair.MoleculairID = tblMoleculair.MoleculairID) 
  3. ON tblAanvraag.AanvraagID = tblAangevraagdMoleculair.AanvraagID 
Looks suspicious to me.

Did you mean
Expand|Select|Wrap|Line Numbers
  1.  FROM tblAanvraag INNER JOIN tblMedewerker ON tblAanvraag.AanvragerID = tblMedewerker.MedewerkerID 
  2.        INNER JOIN tblStatus ON tblAanvraag.StatusCode = tblStatus.StatusCode 
  3.        INNER JOIN tblAangevraagdMoleculair ON tblAanvraag.AanvraagID = tblAangevraagdMoleculair.AanvraagID 
  4.           INNER JOIN tblMoleculair ON tblAangevraagdMoleculair.MoleculairID = tblMoleculair.MoleculairID 
instead?
Jul 29 '08 #2
MrMancunian
569 Expert 512MB
No, I think that part works fine...
Jul 29 '08 #3
r035198x
13,262 8TB
No, I think that part works fine...
Silly me. That First function is not supported in SQL 2000. Is that what you are using? You'd need to use TOP.
Jul 29 '08 #4
MrMancunian
569 Expert 512MB
Silly me. That First function is not supported in SQL 2000. Is that what you are using? You'd need to use TOP.
Ok, how do I use TOP in this query? It tried some things but it keeps telling me it's incorrect syntax.
Jul 29 '08 #5
r035198x
13,262 8TB
Ok, how do I use TOP in this query? It tried some things but it keeps telling me it's incorrect syntax.
If you are solving the top rows per group problem then I suggest you look at this article.
Jul 29 '08 #6
MrMancunian
569 Expert 512MB
If you are solving the top rows per group problem then I suggest you look at this article.
Ok, I changed my query to a working one. Except for one thing. The TOP-part doesn't work the way I want to. Let me explain what it should do. The system I built is a request application for Pathologists. They can request molecular techniques on a tissue sample. More than one technique per sample can be requested. When they request multiple techniques, there should be more than one row in the tblMoleculair selected. As these are all in the same family, it doesn't matter which of the selected tecnhiques get picked. The only problem is that, regardless the chosen technique, it just returns the first name in the table, period. How can I change this, using the following query:

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT 
  2. tblAanvraag.AanvraagID AS Aanvraagnummer,
  3. [PA-Nummer], 
  4. (tblMedewerker.MedewerkerAchternaam+', '+tblMedewerker.MedewerkerVoornaam+' '+tblMedewerker.MedewerkerTussenvoegsel) AS Aanvrager, 
  5. tblAanvraag.Aanvraagdatum AS Aanvraagdatum, 
  6. (SELECT TOP (1) MoleculairKorteNaam FROM tblMoleculair) AS Vraagstelling, 
  7. tblStatus.Status AS Status 
  8. FROM tblAanvraag 
  9. INNER JOIN tblMedewerker ON tblAanvraag.AanvragerID = tblMedewerker.MedewerkerID 
  10. INNER JOIN tblStatus ON tblAanvraag.StatusCode = tblStatus.StatusCode 
  11. INNER JOIN tblAangevraagdMoleculair ON tblAanvraag.AanvraagID = tblAangevraagdMoleculair.AanvraagID 
  12. INNER JOIN tblMoleculair ON tblAangevraagdMoleculair.MoleculairID = tblMoleculair.MoleculairID 
  13. GROUP BY tblAanvraag.AanvraagID, tblAanvraag.[PA-Nummer], 
  14. (tblMedewerker.MedewerkerAchternaam+', '+tblMedewerker.MedewerkerVoornaam+' '+tblMedewerker.MedewerkerTussenvoegsel), 
  15. tblAanvraag.Aanvraagdatum, tblStatus.Status, tblAanvraag.MoleculairePathologie, tblAanvraag.StatusCode 
  16. HAVING tblAanvraag.MoleculairePathologie=1 
  17. AND tblAanvraag.StatusCode<4
Jul 30 '08 #7
MrMancunian
569 Expert 512MB
Dont bother, I already found the solution, using another method.

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT 
  2. tblAanvraag.AanvraagID AS Aanvraagnummer,
  3. [PA-Nummer], 
  4. (tblMedewerker.MedewerkerAchternaam+', '+tblMedewerker.MedewerkerVoornaam+' '+tblMedewerker.MedewerkerTussenvoegsel) AS Aanvrager, 
  5. tblAanvraag.Aanvraagdatum AS Aanvraagdatum, 
  6. MAX(tblMoleculair.MoleculairKorteNaam) AS Vraagstelling, 
  7. tblStatus.Status AS Status 
  8. FROM tblAanvraag 
  9. INNER JOIN tblMedewerker ON tblAanvraag.AanvragerID = tblMedewerker.MedewerkerID 
  10. INNER JOIN tblStatus ON tblAanvraag.StatusCode = tblStatus.StatusCode 
  11. INNER JOIN tblAangevraagdMoleculair ON tblAanvraag.AanvraagID = tblAangevraagdMoleculair.AanvraagID 
  12. INNER JOIN tblMoleculair ON tblAangevraagdMoleculair.MoleculairID = tblMoleculair.MoleculairID
  13. WHERE tblAanvraag.AanvragerID=85 
  14. GROUP BY tblAanvraag.AanvraagID, tblAanvraag.[PA-Nummer], 
  15. (tblMedewerker.MedewerkerAchternaam+', '+tblMedewerker.MedewerkerVoornaam+' '+tblMedewerker.MedewerkerTussenvoegsel), 
  16. tblAanvraag.Aanvraagdatum, tblStatus.Status, tblAanvraag.MoleculairePathologie, tblAanvraag.StatusCode 
  17. HAVING tblAanvraag.MoleculairePathologie=1
  18. ORDER BY tblAanvraag.AanvraagID DESC
Thnx for all the help! :)
Jul 30 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Wescotte | last post by:
Here is a small sample program I wrote in PHP (running off Apache 1.3.31 w/ PHP 5.0.1) to help illustrates problem I'm having. The data base is using DB2 V5R3M0. The client is WinXP machine using...
3
by: Brian Oster | last post by:
After applying security patch MS03-031 (Sql server ver 8.00.818) a query that used to execute in under 2 seconds, now takes over 8 Minutes to complete. Any ideas on what the heck might be going...
1
by: Jeff Blee | last post by:
I hope someone can help me get this graph outputing in proper order. After help from Tom, I got a graph to display output from the previous 12 months and include the average of that output all in...
8
by: Adam Louis | last post by:
I would like help resolving this problem. I'm a novice who's been hired to query a hospital database and extract useful information, available to me only in a dynamically generated, downloadable...
6
by: Martin Lacoste | last post by:
Ok, before I headbutt the computer... don't know why when I add criteria in a query, I get an 'invalid procedure call'. I also don't know why after searching the help in access, the various access...
4
by: Apple | last post by:
1. I want to create an autonumber, my requirement is : 2005/0001 (Year/autonumber), which year & autonumber no. both can auto run. 2. I had create a query by making relation to a table & query,...
11
by: Andy_Khosravi | last post by:
My problem: I'm having trouble with a query taking much too long to run; a query without any criteria evaluating only 650 records takes over 300 seconds to run (over the network. On local drive...
4
by: Konrad Hammerer | last post by:
Hi! I have the following problem: I have a query (a) using another query (b) to get the amount of records of this other query (b), means: select count(MNR) as Number from...
4
by: Stan | last post by:
I am using MS Office Access 2003 (11.5614). My basic question is can I run a query of a query datasheet. I want to use more that one criteria and can not get that query to work. I thought I...
2
by: existential.philosophy | last post by:
This is a new problem for me: I have some queries that open very slowly in design view. My benchmark query takes about 20 minutes to open in design view. That same query takes about 20 minutes...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.