Re: TOP statement doesn't accept a variable
From: Joe Celko (jcelko212_at_earthlink.net)
Date: 09/21/04
- Next message: Louis Davidson: "Re: Join on varchar and int columns"
- Previous message: Alejandro Mesa: "RE: Join on varchar and int columns"
- In reply to: Derek Ruesch: "TOP statement doesn't accept a variable"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 21 Sep 2004 13:41:34 -0700
Firest of all, read ISO-11179 so you will stop using those silly
prefixes on data element names. Your code looks like 1950's FORTRAN or
1960's BASIC and not SQL.
>> It looks like the use of a variable is not allowed in the TOP clause
of a select statement. <<
Yes, and since this a non-relational, proprietary feature it can have
any behavior MS wishes to give it, it can be changed at any time, etc.
This si one of many reasons that good programmers in any language avoid
proprietary features.
>> The following stored procedure is designed to return the
given row number from a query. <<
Well, the whole concept is wrong and you desparately need to read a book
on relational basics. SQL is a set-oriented language. Sets have no
ordering. There are no "row numbers" in a table. Tables are not a
sequential magnetic tape file.
>> If this is the case is there another way to make this stored
procedure work? <<
Use a cursor (which is what SELECT TOP n is under the covers) and go
back to 1950's file processing in SQL, as if you wre still using a 3GL.
Performance will stink and the code will not port; but you wil not have
to learn non-procedural, set-oriented programming which is the whole
idea of SQL.
--CELKO--
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are. Sample data is also a good idea, along with clear
specifications.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
- Next message: Louis Davidson: "Re: Join on varchar and int columns"
- Previous message: Alejandro Mesa: "RE: Join on varchar and int columns"
- In reply to: Derek Ruesch: "TOP statement doesn't accept a variable"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|