ACCESS QUERY TO SQL CONVERSION WITH FIRST KEYWORD HELP!!!

ACCESS QUERY TO SQL CONVERSION WITH FIRST KEYWORD HELP!!!

Post by Daniel En » Thu, 20 Jul 2000 04:00:00



Does anybody know how to rewrite an Access SQL statement that can perform
the same function as follows?

I am having problems with the FIRST expression since SQL doesn't have an
equilavent....


SELECT OrderDetail.DocumentNumber, First(CustomerMaster.Name) AS Customer,
First(CustomerMaster.City) AS City, First(CustomerMaster.State) AS State,
Sum(DeliveryDetail.Cases) AS Cases, Sum(DeliveryDetail.Pounds) AS Weight
FROM CustomerMaster RIGHT JOIN (OrderDetail LEFT JOIN DeliveryDetail ON
(OrderDetail.LineItem = DeliveryDetail.LineItem) AND
(OrderDetail.DocumentNumber = DeliveryDetail.DocumentNumber)) ON
CustomerMaster.CustomerNumber = OrderDetail.SoldToCustomer
GROUP BY OrderDetail.DocumentNumber;

 
 
 

ACCESS QUERY TO SQL CONVERSION WITH FIRST KEYWORD HELP!!!

Post by BPMargoli » Thu, 20 Jul 2000 04:00:00


Daniel,

You have to define "first". The reason SQL (the language) and SQL Server don't
have a FIRST function is because by definition a table is an unordered set of
rows. So the concept of a "first" row is meaningless.

Usually "first" either means ... (a) row entered first in chronological
sequence, or (b) row with lowest value.

For (a), you need to have a column of data type datetime (or smalldatetime) to
locate the earliest row.
For (b), SQL (the language) and SQL Server (and Access) support the MIN
function.

Perhaps you can post which definition you want. It would also help if you would
post table schemas (CREATE TABLEs), some sample data (INSERTs) and the output
you want from the sample data. Code is usually less open to misinterpretation
than is a description of a problem.

---------------------------------------------------------------
BP Margolin
Please reply only to the newsgroups.
When posting, inclusion of SQL (CREATE TABLE ..., INSERT ..., etc) which can be
cut and pasted into Query Analyzer is appreciated.


> Does anybody know how to rewrite an Access SQL statement that can perform
> the same function as follows?

> I am having problems with the FIRST expression since SQL doesn't have an
> equilavent....


> SELECT OrderDetail.DocumentNumber, First(CustomerMaster.Name) AS Customer,
> First(CustomerMaster.City) AS City, First(CustomerMaster.State) AS State,
> Sum(DeliveryDetail.Cases) AS Cases, Sum(DeliveryDetail.Pounds) AS Weight
> FROM CustomerMaster RIGHT JOIN (OrderDetail LEFT JOIN DeliveryDetail ON
> (OrderDetail.LineItem = DeliveryDetail.LineItem) AND
> (OrderDetail.DocumentNumber = DeliveryDetail.DocumentNumber)) ON
> CustomerMaster.CustomerNumber = OrderDetail.SoldToCustomer
> GROUP BY OrderDetail.DocumentNumber;


 
 
 

ACCESS QUERY TO SQL CONVERSION WITH FIRST KEYWORD HELP!!!

Post by Ivan Arjentinsk » Fri, 21 Jul 2000 04:00:00


Definition from Access for First() and Last():
"Because records are usually returned in no particular order (unless the
query includes an ORDER BY clause), the records returned by these functions
will be arbitrary."

So, it is neither (a) nor (b)... :)

Have fun.
--
Ivan Arjentinski
-----------------------------------------------
Please answer only to the newsgroups.
I'll not answer any direct emails.
-----------------------------------------------


> Daniel,

> You have to define "first". The reason SQL (the language) and SQL Server
don't
> have a FIRST function is because by definition a table is an unordered set
of
> rows. So the concept of a "first" row is meaningless.

> Usually "first" either means ... (a) row entered first in chronological
> sequence, or (b) row with lowest value.

> For (a), you need to have a column of data type datetime (or
smalldatetime) to
> locate the earliest row.
> For (b), SQL (the language) and SQL Server (and Access) support the MIN
> function.

> Perhaps you can post which definition you want. It would also help if you
would
> post table schemas (CREATE TABLEs), some sample data (INSERTs) and the
output
> you want from the sample data. Code is usually less open to
misinterpretation
> than is a description of a problem.

> ---------------------------------------------------------------
> BP Margolin
> Please reply only to the newsgroups.
> When posting, inclusion of SQL (CREATE TABLE ..., INSERT ..., etc) which
can be
> cut and pasted into Query Analyzer is appreciated.



> > Does anybody know how to rewrite an Access SQL statement that can
perform
> > the same function as follows?

> > I am having problems with the FIRST expression since SQL doesn't have an
> > equilavent....


> > SELECT OrderDetail.DocumentNumber, First(CustomerMaster.Name) AS
Customer,
> > First(CustomerMaster.City) AS City, First(CustomerMaster.State) AS
State,
> > Sum(DeliveryDetail.Cases) AS Cases, Sum(DeliveryDetail.Pounds) AS Weight
> > FROM CustomerMaster RIGHT JOIN (OrderDetail LEFT JOIN DeliveryDetail ON
> > (OrderDetail.LineItem = DeliveryDetail.LineItem) AND
> > (OrderDetail.DocumentNumber = DeliveryDetail.DocumentNumber)) ON
> > CustomerMaster.CustomerNumber = OrderDetail.SoldToCustomer
> > GROUP BY OrderDetail.DocumentNumber;

 
 
 

ACCESS QUERY TO SQL CONVERSION WITH FIRST KEYWORD HELP!!!

Post by BPMargoli » Fri, 21 Jul 2000 04:00:00


Ivan,

Oh no ... you have just given Joe Celko additional ammunition to rant and rave
against Access. Lord help us all if Joe reads the word "records" in the
definition you posted. Another lecture on (1) it's rows not records, (2) Access
is the invention of Satan, and (3) how Atlanta programmers get $1250 per day to
convert Access SQL to "real" SQL (ya know, the type used by "REAL MEN")   :-)

---------------------------------------------------------------
BP Margolin
Please reply only to the newsgroups.
When posting, inclusion of SQL (CREATE TABLE ..., INSERT ..., etc) which can be
cut and pasted into Query Analyzer is appreciated.


> Definition from Access for First() and Last():
> "Because records are usually returned in no particular order (unless the
> query includes an ORDER BY clause), the records returned by these functions
> will be arbitrary."

> So, it is neither (a) nor (b)... :)

> Have fun.
> --
> Ivan Arjentinski
> -----------------------------------------------
> Please answer only to the newsgroups.
> I'll not answer any direct emails.
> -----------------------------------------------



> > Daniel,

> > You have to define "first". The reason SQL (the language) and SQL Server
> don't
> > have a FIRST function is because by definition a table is an unordered set
> of
> > rows. So the concept of a "first" row is meaningless.

> > Usually "first" either means ... (a) row entered first in chronological
> > sequence, or (b) row with lowest value.

> > For (a), you need to have a column of data type datetime (or
> smalldatetime) to
> > locate the earliest row.
> > For (b), SQL (the language) and SQL Server (and Access) support the MIN
> > function.

> > Perhaps you can post which definition you want. It would also help if you
> would
> > post table schemas (CREATE TABLEs), some sample data (INSERTs) and the
> output
> > you want from the sample data. Code is usually less open to
> misinterpretation
> > than is a description of a problem.

> > ---------------------------------------------------------------
> > BP Margolin
> > Please reply only to the newsgroups.
> > When posting, inclusion of SQL (CREATE TABLE ..., INSERT ..., etc) which
> can be
> > cut and pasted into Query Analyzer is appreciated.



> > > Does anybody know how to rewrite an Access SQL statement that can
> perform
> > > the same function as follows?

> > > I am having problems with the FIRST expression since SQL doesn't have an
> > > equilavent....


> > > SELECT OrderDetail.DocumentNumber, First(CustomerMaster.Name) AS
> Customer,
> > > First(CustomerMaster.City) AS City, First(CustomerMaster.State) AS
> State,
> > > Sum(DeliveryDetail.Cases) AS Cases, Sum(DeliveryDetail.Pounds) AS Weight
> > > FROM CustomerMaster RIGHT JOIN (OrderDetail LEFT JOIN DeliveryDetail ON
> > > (OrderDetail.LineItem = DeliveryDetail.LineItem) AND
> > > (OrderDetail.DocumentNumber = DeliveryDetail.DocumentNumber)) ON
> > > CustomerMaster.CustomerNumber = OrderDetail.SoldToCustomer
> > > GROUP BY OrderDetail.DocumentNumber;

 
 
 

ACCESS QUERY TO SQL CONVERSION WITH FIRST KEYWORD HELP!!!

Post by Ivan Arjentinsk » Sat, 22 Jul 2000 04:00:00


Quote:> Oh no ... you have just given Joe Celko additional ammunition to rant and
rave
> against Access. Lord help us all if Joe reads the word "records" in the
> definition you posted.

EXCACTLY for this reason I always go twice through any of my posts searching
for some
sneaked "record" and "field" and change it to "row" and "column" :)

However this was direct copy & paste from Access help and I don't want to
change MS words.
--
Ivan Arjentinski

P.S. I hope Joe is not using Find function with "record" and "field" and
then paste a prepared rant... :)

-----------------------------------------------
Please answer only to the newsgroups.
I'll not answer any direct emails.
-----------------------------------------------


> Ivan,

> Oh no ... you have just given Joe Celko additional ammunition to rant and
rave
> against Access. Lord help us all if Joe reads the word "records" in the
> definition you posted. Another lecture on (1) it's rows not records, (2)
Access
> is the invention of Satan, and (3) how Atlanta programmers get $1250 per
day to
> convert Access SQL to "real" SQL (ya know, the type used by "REAL MEN")
:-)

> ---------------------------------------------------------------
> BP Margolin
> Please reply only to the newsgroups.
> When posting, inclusion of SQL (CREATE TABLE ..., INSERT ..., etc) which
can be
> cut and pasted into Query Analyzer is appreciated.



> > Definition from Access for First() and Last():
> > "Because records are usually returned in no particular order (unless the
> > query includes an ORDER BY clause), the records returned by these
functions
> > will be arbitrary."

> > So, it is neither (a) nor (b)... :)

> > Have fun.
> > --
> > Ivan Arjentinski
> > -----------------------------------------------
> > Please answer only to the newsgroups.
> > I'll not answer any direct emails.
> > -----------------------------------------------



> > > Daniel,

> > > You have to define "first". The reason SQL (the language) and SQL
Server
> > don't
> > > have a FIRST function is because by definition a table is an unordered
set
> > of
> > > rows. So the concept of a "first" row is meaningless.

> > > Usually "first" either means ... (a) row entered first in
chronological
> > > sequence, or (b) row with lowest value.

> > > For (a), you need to have a column of data type datetime (or
> > smalldatetime) to
> > > locate the earliest row.
> > > For (b), SQL (the language) and SQL Server (and Access) support the
MIN
> > > function.

> > > Perhaps you can post which definition you want. It would also help if
you
> > would
> > > post table schemas (CREATE TABLEs), some sample data (INSERTs) and the
> > output
> > > you want from the sample data. Code is usually less open to
> > misinterpretation
> > > than is a description of a problem.

> > > ---------------------------------------------------------------
> > > BP Margolin
> > > Please reply only to the newsgroups.
> > > When posting, inclusion of SQL (CREATE TABLE ..., INSERT ..., etc)
which
> > can be
> > > cut and pasted into Query Analyzer is appreciated.



> > > > Does anybody know how to rewrite an Access SQL statement that can
> > perform
> > > > the same function as follows?

> > > > I am having problems with the FIRST expression since SQL doesn't
have an
> > > > equilavent....


> > > > SELECT OrderDetail.DocumentNumber, First(CustomerMaster.Name) AS
> > Customer,
> > > > First(CustomerMaster.City) AS City, First(CustomerMaster.State) AS
> > State,
> > > > Sum(DeliveryDetail.Cases) AS Cases, Sum(DeliveryDetail.Pounds) AS
Weight
> > > > FROM CustomerMaster RIGHT JOIN (OrderDetail LEFT JOIN DeliveryDetail
ON
> > > > (OrderDetail.LineItem = DeliveryDetail.LineItem) AND
> > > > (OrderDetail.DocumentNumber = DeliveryDetail.DocumentNumber)) ON
> > > > CustomerMaster.CustomerNumber = OrderDetail.SoldToCustomer
> > > > GROUP BY OrderDetail.DocumentNumber;

 
 
 

ACCESS QUERY TO SQL CONVERSION WITH FIRST KEYWORD HELP!!!

Post by BPMargoli » Sat, 22 Jul 2000 04:00:00


Ivan,

:-)

I was perusing an old Chris Date book the other day ... "A Guide to DB2" ... it
was actually my first introduction to SQL ... and came across the following ...

"Note that we use the terms "record" and "row" interchangeably, and the terms
"field" and "column" likewise."

I was all prepared to post this next time Joe ranted and raved about record/row,
field/column ... but thought better of it.

BPM


> > Oh no ... you have just given Joe Celko additional ammunition to rant and
> rave
> > against Access. Lord help us all if Joe reads the word "records" in the
> > definition you posted.

> EXCACTLY for this reason I always go twice through any of my posts searching
> for some
> sneaked "record" and "field" and change it to "row" and "column" :)

> However this was direct copy & paste from Access help and I don't want to
> change MS words.
> --
> Ivan Arjentinski

> P.S. I hope Joe is not using Find function with "record" and "field" and
> then paste a prepared rant... :)

> -----------------------------------------------
> Please answer only to the newsgroups.
> I'll not answer any direct emails.
> -----------------------------------------------



> > Ivan,

> > Oh no ... you have just given Joe Celko additional ammunition to rant and
> rave
> > against Access. Lord help us all if Joe reads the word "records" in the
> > definition you posted. Another lecture on (1) it's rows not records, (2)
> Access
> > is the invention of Satan, and (3) how Atlanta programmers get $1250 per
> day to
> > convert Access SQL to "real" SQL (ya know, the type used by "REAL MEN")
> :-)

> > ---------------------------------------------------------------
> > BP Margolin
> > Please reply only to the newsgroups.
> > When posting, inclusion of SQL (CREATE TABLE ..., INSERT ..., etc) which
> can be
> > cut and pasted into Query Analyzer is appreciated.



> > > Definition from Access for First() and Last():
> > > "Because records are usually returned in no particular order (unless the
> > > query includes an ORDER BY clause), the records returned by these
> functions
> > > will be arbitrary."

> > > So, it is neither (a) nor (b)... :)

> > > Have fun.
> > > --
> > > Ivan Arjentinski
> > > -----------------------------------------------
> > > Please answer only to the newsgroups.
> > > I'll not answer any direct emails.
> > > -----------------------------------------------



> > > > Daniel,

> > > > You have to define "first". The reason SQL (the language) and SQL
> Server
> > > don't
> > > > have a FIRST function is because by definition a table is an unordered
> set
> > > of
> > > > rows. So the concept of a "first" row is meaningless.

> > > > Usually "first" either means ... (a) row entered first in
> chronological
> > > > sequence, or (b) row with lowest value.

> > > > For (a), you need to have a column of data type datetime (or
> > > smalldatetime) to
> > > > locate the earliest row.
> > > > For (b), SQL (the language) and SQL Server (and Access) support the
> MIN
> > > > function.

> > > > Perhaps you can post which definition you want. It would also help if
> you
> > > would
> > > > post table schemas (CREATE TABLEs), some sample data (INSERTs) and the
> > > output
> > > > you want from the sample data. Code is usually less open to
> > > misinterpretation
> > > > than is a description of a problem.

> > > > ---------------------------------------------------------------
> > > > BP Margolin
> > > > Please reply only to the newsgroups.
> > > > When posting, inclusion of SQL (CREATE TABLE ..., INSERT ..., etc)
> which
> > > can be
> > > > cut and pasted into Query Analyzer is appreciated.



> > > > > Does anybody know how to rewrite an Access SQL statement that can
> > > perform
> > > > > the same function as follows?

> > > > > I am having problems with the FIRST expression since SQL doesn't
> have an
> > > > > equilavent....


> > > > > SELECT OrderDetail.DocumentNumber, First(CustomerMaster.Name) AS
> > > Customer,
> > > > > First(CustomerMaster.City) AS City, First(CustomerMaster.State) AS
> > > State,
> > > > > Sum(DeliveryDetail.Cases) AS Cases, Sum(DeliveryDetail.Pounds) AS
> Weight
> > > > > FROM CustomerMaster RIGHT JOIN (OrderDetail LEFT JOIN DeliveryDetail
> ON
> > > > > (OrderDetail.LineItem = DeliveryDetail.LineItem) AND
> > > > > (OrderDetail.DocumentNumber = DeliveryDetail.DocumentNumber)) ON
> > > > > CustomerMaster.CustomerNumber = OrderDetail.SoldToCustomer
> > > > > GROUP BY OrderDetail.DocumentNumber;

 
 
 

1. Access to SQL Server 7 Query conversion with FIRST Keyword

Does anybody know how to rewrite an Access SQL statement that can perform
the same function as follows?

I am having problems with the FIRST expression since SQL doesn't have an
equilavent....


SELECT OrderDetail.DocumentNumber, First(CustomerMaster.Name) AS Customer,
First(CustomerMaster.City) AS City, First(CustomerMaster.State) AS State,
Sum(DeliveryDetail.Cases) AS Cases, Sum(DeliveryDetail.Pounds) AS Weight
FROM CustomerMaster RIGHT JOIN (OrderDetail LEFT JOIN DeliveryDetail ON
(OrderDetail.LineItem = DeliveryDetail.LineItem) AND
(OrderDetail.DocumentNumber = DeliveryDetail.DocumentNumber)) ON
CustomerMaster.CustomerNumber = OrderDetail.SoldToCustomer
GROUP BY OrderDetail.DocumentNumber;

2. Using BLAT.dll

3. First keyword in Access any comparable keyword in SQLServer

4. How do you get rid of ...

5. Access / ANSI SQL - Help with Comparitive keywords

6. US-NC-Charlotte- Oracle DBA / PeopleTools programming

7. Convert FIRST in Access query to SQL

8. Conversion of Access queries to SQL Server procedures

9. HELP: First Day in Week Setting and First Week in Year Help

10. Text Conversion to First Char Upper case in DTS or SQL

11. Comparison of ANSI SQL and Access SQL keywords