473,657 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access to SQL Server Query Translation

Hi,

I'm trying to convert MS Access 97 .mdb application to Access 2003 .adp
application with SQL Server as Backend.

I'm having trouble converting Access Query into SQL Query. The Query is
given below:

~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~
SELECT DISTINCTROW Buildings.Build ingNumber,
First(Buildings .BuildingName) AS FirstOfBuilding Name,
First(Ownership Codes.Ownership Code) AS FirstOfOwnershi pCode,
First(Ownership Codes.Ownership Desc) AS FirstOfOwnershi pDesc,
First(CityCodes .CityName) AS FirstOfCityName ,
First(CountyCod es.CountyName) AS FirstOfCountyNa me,
First(Buildings .Address) AS FirstOfAddress,
First(Buildings .YearConstructe d) AS FirstOfYearCons tructed,
First(Buildings .DateOccupancy) AS FirstOfDateOccu pancy,
First(Buildings .NumberLevels) AS FirstOfNumberLe vels,
First(Buildings .BasicGrossArea ) AS FirstOfBasicGro ssArea,
Sum(Rooms.Assig nableSquareFeet ) AS SumOfAssignable SquareFeet,
First(Buildings .UnrelatedGross Area) AS FirstOfUnrelate dGrossArea,
First(Buildings .SpecialArea) AS FirstOfSpecialA rea,
First(Buildings .CoveredUnenclo sedGrossArea) AS
FirstOfCoveredU nenclosedGrossA rea
FROM CountyCodes INNER JOIN (OwnershipCodes INNER JOIN (ConditionCodes
INNER JOIN ((CityCodes INNER JOIN Buildings ON CityCodes.CityC ode =
Buildings.CityC ode) LEFT JOIN Rooms ON Buildings.Build ingNumber =
Rooms.BuildingN umber) ON ConditionCodes. ConditionCode =
Buildings.Condi tionCode) ON OwnershipCodes. OwnershipCode =
Buildings.Owner shipCode) ON CountyCodes.Cou ntyCode =
CityCodes.Count yCode
GROUP BY Buildings.Build ingNumber;

~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~

Please can any one tell me substitue for First Function in Acess to SQL
Function.

Any help is appreciated.
Thanks,
S

Aug 17 '06 #1
3 4427
(s_******@berke ley.edu) writes:
I'm trying to convert MS Access 97 .mdb application to Access 2003 .adp
application with SQL Server as Backend.

I'm having trouble converting Access Query into SQL Query. The Query is
given below:

~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~
SELECT DISTINCTROW Buildings.Build ingNumber,
First(Buildings .BuildingName) AS FirstOfBuilding Name,
First(Ownership Codes.Ownership Code) AS FirstOfOwnershi pCode,
First(Ownership Codes.Ownership Desc) AS FirstOfOwnershi pDesc,
First(CityCodes .CityName) AS FirstOfCityName ,
First(CountyCod es.CountyName) AS FirstOfCountyNa me,
First(Buildings .Address) AS FirstOfAddress,
First(Buildings .YearConstructe d) AS FirstOfYearCons tructed,
First(Buildings .DateOccupancy) AS FirstOfDateOccu pancy,
First(Buildings .NumberLevels) AS FirstOfNumberLe vels,
First(Buildings .BasicGrossArea ) AS FirstOfBasicGro ssArea,
Sum(Rooms.Assig nableSquareFeet ) AS SumOfAssignable SquareFeet,
First(Buildings .UnrelatedGross Area) AS FirstOfUnrelate dGrossArea,
First(Buildings .SpecialArea) AS FirstOfSpecialA rea,
First(Buildings .CoveredUnenclo sedGrossArea) AS
FirstOfCoveredU nenclosedGrossA rea
FROM CountyCodes INNER JOIN (OwnershipCodes INNER JOIN (ConditionCodes
INNER JOIN ((CityCodes INNER JOIN Buildings ON CityCodes.CityC ode =
Buildings.CityC ode) LEFT JOIN Rooms ON Buildings.Build ingNumber =
Rooms.BuildingN umber) ON ConditionCodes. ConditionCode =
Buildings.Condi tionCode) ON OwnershipCodes. OwnershipCode =
Buildings.Owner shipCode) ON CountyCodes.Cou ntyCode =
CityCodes.Count yCode
GROUP BY Buildings.Build ingNumber;

~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~

Please can any one tell me substitue for First Function in Acess to SQL
Function.
I don't know Access, but if I have understood it correctcly, First
returns the value for the "first" row in the group. What I don't know
if you are guaranteed that all these "first" will return data from the
same row from Buildings, or if they could be from different rows.

You see, in a relational database "first" is a not meaningful operation.
A table is a set of unordered tuples, and there is no first or last.

It could help if you posted the CREATE TABLE statements for the table,
including definitions of primary keys and foreign keys. It's also a good
idea to add a short description of what the query is supposed to achieve.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Aug 17 '06 #2
To add on to Erland's response, FIRST is not relational so there is no
direct SQL Server equivalent. I have seen FIRST most often used in Access
queries to mask problems with data or query formulation rather than to
address a real requirement.

It looks to me like the purpose of this query is to calculate the total
assignable square feet by building and include additional information
related to the building. In that case, you might try something like the
example below, which assumes the primary key and foreign key relationships
are on the joined columns:

SELECT
Buildings.Build ingNumber,
Buildings.Build ingName,
First(Ownership Codes.Ownership Code,
OwnershipCodes. OwnershipDesc,
CityCodes.CityN ame,
CountyCodes.Cou ntyName,
Buildings.Addre ss,
Buildings.YearC onstructed,
Buildings.DateO ccupancy,
Buildings.Numbe rLevels,
Buildings.Basic GrossArea,
(SELECT SUM(Rooms.Assig nableSquareFeet )
FROM Rooms
WHERE Buildings.Build ingNumber = Rooms.BuildingN umber
) AS SumOfAssignable SquareFeet,
Buildings.Unrel atedGrossArea,
Buildings.Speci alArea,
Buildings.Cover edUnenclosedGro ssArea
FROM Buildings
INNER JOIN CountyCodes
ON CityCodes.CityC ode = Buildings.CityC ode
INNER JOIN OwnershipCodes
ON OwnershipCodes. OwnershipCode = Buildings.Owner shipCode
INNER JOIN ConditionCodes
ON ConditionCodes. ConditionCode = Buildings.Condi tionCode
INNER JOIN CityCodes
ON CountyCodes.Cou ntyCode = CityCodes.Count yCode;

--
Hope this helps.

Dan Guzman
SQL Server MVP

<s_******@berke ley.eduwrote in message
news:11******** ************@m7 3g2000cwd.googl egroups.com...
Hi,

I'm trying to convert MS Access 97 .mdb application to Access 2003 .adp
application with SQL Server as Backend.

I'm having trouble converting Access Query into SQL Query. The Query is
given below:

~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~
SELECT DISTINCTROW Buildings.Build ingNumber,
First(Buildings .BuildingName) AS FirstOfBuilding Name,
First(Ownership Codes.Ownership Code) AS FirstOfOwnershi pCode,
First(Ownership Codes.Ownership Desc) AS FirstOfOwnershi pDesc,
First(CityCodes .CityName) AS FirstOfCityName ,
First(CountyCod es.CountyName) AS FirstOfCountyNa me,
First(Buildings .Address) AS FirstOfAddress,
First(Buildings .YearConstructe d) AS FirstOfYearCons tructed,
First(Buildings .DateOccupancy) AS FirstOfDateOccu pancy,
First(Buildings .NumberLevels) AS FirstOfNumberLe vels,
First(Buildings .BasicGrossArea ) AS FirstOfBasicGro ssArea,
Sum(Rooms.Assig nableSquareFeet ) AS SumOfAssignable SquareFeet,
First(Buildings .UnrelatedGross Area) AS FirstOfUnrelate dGrossArea,
First(Buildings .SpecialArea) AS FirstOfSpecialA rea,
First(Buildings .CoveredUnenclo sedGrossArea) AS
FirstOfCoveredU nenclosedGrossA rea
FROM CountyCodes INNER JOIN (OwnershipCodes INNER JOIN (ConditionCodes
INNER JOIN ((CityCodes INNER JOIN Buildings ON CityCodes.CityC ode =
Buildings.CityC ode) LEFT JOIN Rooms ON Buildings.Build ingNumber =
Rooms.BuildingN umber) ON ConditionCodes. ConditionCode =
Buildings.Condi tionCode) ON OwnershipCodes. OwnershipCode =
Buildings.Owner shipCode) ON CountyCodes.Cou ntyCode =
CityCodes.Count yCode
GROUP BY Buildings.Build ingNumber;

~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~

Please can any one tell me substitue for First Function in Acess to SQL
Function.

Any help is appreciated.
Thanks,
S

Aug 20 '06 #3
First(Ownership Codes.Ownership Code,
Oops, missed one. Should be:

OwnershipCodes. OwnershipCode,

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Dan Guzman" <gu******@nospa m-online.sbcgloba l.netwrote in message
news:pC******** ********@newssv r14.news.prodig y.com...
To add on to Erland's response, FIRST is not relational so there is no
direct SQL Server equivalent. I have seen FIRST most often used in Access
queries to mask problems with data or query formulation rather than to
address a real requirement.

It looks to me like the purpose of this query is to calculate the total
assignable square feet by building and include additional information
related to the building. In that case, you might try something like the
example below, which assumes the primary key and foreign key relationships
are on the joined columns:

SELECT
Buildings.Build ingNumber,
Buildings.Build ingName,
First(Ownership Codes.Ownership Code,
OwnershipCodes. OwnershipDesc,
CityCodes.CityN ame,
CountyCodes.Cou ntyName,
Buildings.Addre ss,
Buildings.YearC onstructed,
Buildings.DateO ccupancy,
Buildings.Numbe rLevels,
Buildings.Basic GrossArea,
(SELECT SUM(Rooms.Assig nableSquareFeet )
FROM Rooms
WHERE Buildings.Build ingNumber = Rooms.BuildingN umber
) AS SumOfAssignable SquareFeet,
Buildings.Unrel atedGrossArea,
Buildings.Speci alArea,
Buildings.Cover edUnenclosedGro ssArea
FROM Buildings
INNER JOIN CountyCodes
ON CityCodes.CityC ode = Buildings.CityC ode
INNER JOIN OwnershipCodes
ON OwnershipCodes. OwnershipCode = Buildings.Owner shipCode
INNER JOIN ConditionCodes
ON ConditionCodes. ConditionCode = Buildings.Condi tionCode
INNER JOIN CityCodes
ON CountyCodes.Cou ntyCode = CityCodes.Count yCode;

--
Hope this helps.

Dan Guzman
SQL Server MVP

<s_******@berke ley.eduwrote in message
news:11******** ************@m7 3g2000cwd.googl egroups.com...
>Hi,

I'm trying to convert MS Access 97 .mdb application to Access 2003 .adp
application with SQL Server as Backend.

I'm having trouble converting Access Query into SQL Query. The Query is
given below:

~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~
SELECT DISTINCTROW Buildings.Build ingNumber,
First(Building s.BuildingName) AS FirstOfBuilding Name,
First(Ownershi pCodes.Ownershi pCode) AS FirstOfOwnershi pCode,
First(Ownershi pCodes.Ownershi pDesc) AS FirstOfOwnershi pDesc,
First(CityCode s.CityName) AS FirstOfCityName ,
First(CountyCo des.CountyName) AS FirstOfCountyNa me,
First(Building s.Address) AS FirstOfAddress,
First(Building s.YearConstruct ed) AS FirstOfYearCons tructed,
First(Building s.DateOccupancy ) AS FirstOfDateOccu pancy,
First(Building s.NumberLevels) AS FirstOfNumberLe vels,
First(Building s.BasicGrossAre a) AS FirstOfBasicGro ssArea,
Sum(Rooms.Assi gnableSquareFee t) AS SumOfAssignable SquareFeet,
First(Building s.UnrelatedGros sArea) AS FirstOfUnrelate dGrossArea,
First(Building s.SpecialArea) AS FirstOfSpecialA rea,
First(Building s.CoveredUnencl osedGrossArea) AS
FirstOfCovered UnenclosedGross Area
FROM CountyCodes INNER JOIN (OwnershipCodes INNER JOIN (ConditionCodes
INNER JOIN ((CityCodes INNER JOIN Buildings ON CityCodes.CityC ode =
Buildings.City Code) LEFT JOIN Rooms ON Buildings.Build ingNumber =
Rooms.Building Number) ON ConditionCodes. ConditionCode =
Buildings.Cond itionCode) ON OwnershipCodes. OwnershipCode =
Buildings.Owne rshipCode) ON CountyCodes.Cou ntyCode =
CityCodes.Coun tyCode
GROUP BY Buildings.Build ingNumber;

~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~

Please can any one tell me substitue for First Function in Acess to SQL
Function.

Any help is appreciated.
Thanks,
S


Aug 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2948
by: Frnak McKenney | last post by:
Back when computer dinosaurs roamed the earth and the precursors to today's Internet were tiny flocks of TDMs living symbiotically with the silicon giants, tracking access to data processing resources was much simpler: you logged in with a userID and password, and when you were done you ended your session by logging out (or occasionally by being disconnected). Connection time was easy to measure, and it made sense to both the customer...
6
3428
by: Jegger | last post by:
Hello! We have following situation; network with 100 users, aplication developed in Access, user DB deployed on SQL Server. Is it better to create query inside aplication (with code) and then pass it to SQL Server for execution or is it better to have all these queries saved like stored procedures and then called from aplication?
4
2299
by: Bon | last post by:
Hello all Would it be possible to migrate the MS Access 2000 to MS SQL Server 2000? My application is using MS Access 2000 as database and as user interface such as forms. Now, I want to migrate the backend database from MS Access 2000 to MS SQL Server 2000. However, I want to keep the MS Access 2000 interface. Would it be possible?
3
23451
by: Jon Ole Hedne | last post by:
My Access 2002-application need to work with tables from both Oracle and Access. To solve this, I want to run some querys on three views in Oracle and import the results into temporary Access-tables. I have tried this: conn.Provider = "Microsoft.Jet.OLEDB.4.0" conn.ConnectionString = "data source=" & datafil & ";Jet OLEDB:Database Password=" conn.Open datafil
29
3690
by: Mark B | last post by:
We have an Access app (quite big) at www.orbisoft.com/download. We have had requests by potential users to have it converted to an SQL version for them since there corporate policy excludes them from buying mdb backends. Here's the (million dollar?) questions :) How long and how difficult a process would it be? Which SQL platform would we be best to develop it on?
3
1744
by: Rahul Agarwal | last post by:
Hi In our web page we use a combination of HTML and server side controls and some of them have a custom attribute based on which we need to find and replace the values once the HTML is ready. For e.g. <LABEL DICTCODE="XYZ">Some text</LABEL> At run time just before the complete HTML is sent to the client-side I want to get hold of the HTML so that I can find and replace all the HTML elements
11
4593
by: DraguVaso | last post by:
Hi, I want to make a small application in VB.NET that relinks all the query's and tables in an Access database that are linked via ODBC to an SQL Server. It must be able to relink all the tables and query's to a given databse, on a given sql server with given login and password. Aybody knows how to do that, or better: has a sample application doing this? Thanks in advance!
6
4398
by: jsacrey | last post by:
Hey everybody, got a secnario for ya that I need a bit of help with. Access 97 using linked tables from an SQL Server 2000 machine. I've created a simple query using two tables joined by one field between them. The join field in both tables are indexed and I'm selecting 1 field from each table to lookup. The Access query is taking more than 60 second to retrieve 1 record and if I execute the same query within the Query Analyzer, it...
13
3724
by: magickarle | last post by:
Hi, I got a pass-through query (that takes about 15 mins to process) I would like to integrate variables to it. IE: something simple: Select EmplID from empl_Lst where empl_lst.timestamp between !! And !! Not sure how to do so (should it be a query in Access or a macro) The connection would be ODBC.
0
8385
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8303
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8723
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7316
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.