Re: Difficult Query: is this possible in SQL?
Erland,
[color=blue][color=green]
>>If the product does absolutely silly things, you don't have no choice<<[/color][/color]
I have in my hand a SQL Server 1.0 manual dated 1989. Across the top of the
front cover it says "Microsoft" (and Ashton-Tate <g>). If the product did
absolutely silly things Microsoft never should have put their name on it -
and then maintained the *faulty* logic for 10 years before deciding, all of
a sudden, that the behavior was suddenly unacceptable.
In any case, in addition to the *absolutely silly things* that it did, it
also did perfectly reasonable things. One small example - the original
PATINDEX function returned a 0 if a match was made beginning with the 1st
character of a string. Then somebody noticed that the CHARINDEX function
returned a 1 on a 1st character match. Thinking that it would be nice for
these 2 similar functions to work the same way, they simply changed the
PATINDEX function. It wasn't even a documented change. That was a long time
ago, but I still remember very well what happened to my code. Just a small
example of many - and has nothing to do with ANSI compliance.
A more recent example was a *feature* introduced in release 7. Somebody
decided that the ARITHABORT command was really only to be taken seriously
for SELECT statements and should be ignored for INSERT and UPDATE
statements. This was also (initially) an undocumented feature. This really
wasn't very nice for those of us who process million row inserts at night
which include arithmetic calculations on some of the columns. Microsoft
refused to fix this until SQL 2000. That one *feature* alone made 7.0 an
unusable product for us.
[color=blue][color=green]
>>the keyword is ANSI. Microsoft wanted their product to adhere more to ANSI[/color][/color]
standards<<
Erland, that is Microsoft's line and the excuse they use every time they
deliberately break something. The bottom line here is they are very
selective about WHICH ANSI rules they choose to implement and which they
conveniently ignore. If you don't believe it, call up your friends on the
development team and remind them that FROM clauses are illegal in UPDATE and
DELETE statements and they really shouldn't allow this non-ANSI behavior in
their product. Be sure to report back what they say.
[color=blue][color=green]
>>...when you port from other products...<<[/color][/color]
This is my favorite. How many products have stored procedures written in
TSQL? OK, SYBASE at least started out the same - but that was a long time
ago. When's the last time you tried to port a SYBASE stored procedure into
SQL Server? Oracle? Anybody? When's the last time you tried to port a SQL
Server stored procedure to any other database? I just love hearing about
portability!
Erland, there's nothing wrong with enhancements. Add all the features you
want but don't break my old code in the process. And don't tell me that
everything you do is to improve ANSI compliance. It's true sometimes, but
ONLY sometimes.
Microsoft simply has a terrible track record when it comes to backward
compatibility. I've been burned so many times you'll never convince me
otherwise.
In any case, what started this whole discussion was a query example that
only worked with defaults configured a particular way. I maintain that if
you code that way you will eventually be punished by Microsoft for trusting
them. It happens with almost every new release.
Richard
"Erland Sommarskog" <esquel@sommars kog.se> wrote in message
news:Xns951FF02 0B5D10Yazorman@ 127.0.0.1...[color=blue]
> Richard Romley (richardromley@ optonline.net) writes:[color=green]
> > Hmmm. Where have I heard that before? There is ALWAYS a good reason to
> > change defaults. There is ALWAYS a good reason to change the behavior of
> > existing code. Well, there is also one very good reason NOT to - doing[/color][/color]
so[color=blue][color=green]
> > breaks all the code that's been written since the beginning of time that
> > depended on the old rules.[/color]
>
> If the product does absolutely silly things, you don't have no choice. For
> instance in SQL Server 4.x you could say:
>
> SELECT a, b, COUNT(*)
> FROM tbl
> GROUP BY a
>
> Both Sybase and Microsoft outlawed this syntax in System 10 and SQL
> Server 6 respectively.
>
> For the issues we discuss, the keyword is ANSI. Microsoft wanted their
> product to adhere more to ANSI standards, and this certainly applies
> to existing code, to wit when you port from other products. However,
> MS did not go all the way. If you say SET ANSI_DEFAULTS ON, there are
> a couple of settings which are set, and I will add ARITHABORT and
> CONCAT_NULL_YIE LDS_NULL to these.
>
> ANSI_NULL_DLFT_ ON - this setting controls what happens if you create
> a column in a table without specify explicit nullability. Since none
> of NOT NULL or NULL is obvious, good practice is always state this
> explicitly.
>
> ANSI_PADDING - this column affects how trailing spaces are saved for
> varchar values. It is not likely to affect that many appliactions.
>
> ANSI_WARNINGS - the most important effect is that you get an error if
> you try to store a value that does not fir into a char/binary column.
> It does affect some application, but there is no dramatic issue. The
> other things caused by ANSI_WARNINGS is likely to have even lower impact.
>
> ARITHABORT - Few would probably complain that their division with zero
> yields an error (this also comes with ANSI_WARNINGS). Most probably
> find it a good thing.
>
> QUOTED_IDENTIFI ER - Now, here is one that with a huge impact, since
> strings quoted by " suddenly became identifiers. Mitigating, though, is
> that this can be fixed mechanically.
>
> ANSI_NULLS - This is an setting that should have absolutely no effect on
> properly written code. @x = NULL was wrong in 4.x days, it has always
> been wrong, it was just that Sybase out of folly handled NULL as equal
> to NULL. But of course, a system where the programmers did not have
> understanding of NULL values takes a serious toll here. But as I said
> the Best Practice Analyzer can help you out here.
>
> CONCAT_NULL_YIE LDS_NULL - Exactly the same thing applies here: on a
> properly implemented system, this is not an issue.
>
> ............... .....
>
> IMPLICIT_TRANSA CTIONS - Now here is one! This option is OFF by default,
> and had MS made this the default, about every application out there would
> have succumbed. Right or wrong, auto-commit has always been the way Sybase
> and SQL Server has gone.
>
> CURSOR_CLOSE_ON _COMMIT - This option is OFF by default as well. Since
> cursors are something you should not use anyway, it should have less
> impact. But the whole idea sounds corny to me. I might have a transaction
> for each iteration in the cursor. Certainly I don't want it close.
>
> So Microsoft acted judiciously when they decided what should be on by
> default and what should not. ANSI_NULLS and CONCAT_NULL_YIE LDS_NULL
> may have a great impact your code, but let me again stress that the
> original defaults were just plain wrong and indefensible to have in
> an engine to aspire to be an enterprise DBMS.
>[color=green]
> > Microsoft has proven time and time again that they simply don't give a
> > damn about the harm they inflict on their customers every time they do
> > that.[/color]
>
> Since I have good contacts with the SQL Server team, I can assure you
> that they are very anxious about compability. Very anxious.
>
> But if you have ever worked with product development, you also know that
> sometimes maintaining old functionality can be a true burden. (If you
> work for a site where you only have one production environment, this is
> not an issue for you. You can rip things out as you please.)
>
>
>
> --
> Erland Sommarskog, SQL Server MVP, esquel@sommarsk og.se
>
> Books Online for SQL Server SP3 at
> http://www.microsoft.com/sql/techinf...2000/books.asp[/color]
Erland,
[color=blue][color=green]
>>If the product does absolutely silly things, you don't have no choice<<[/color][/color]
I have in my hand a SQL Server 1.0 manual dated 1989. Across the top of the
front cover it says "Microsoft" (and Ashton-Tate <g>). If the product did
absolutely silly things Microsoft never should have put their name on it -
and then maintained the *faulty* logic for 10 years before deciding, all of
a sudden, that the behavior was suddenly unacceptable.
In any case, in addition to the *absolutely silly things* that it did, it
also did perfectly reasonable things. One small example - the original
PATINDEX function returned a 0 if a match was made beginning with the 1st
character of a string. Then somebody noticed that the CHARINDEX function
returned a 1 on a 1st character match. Thinking that it would be nice for
these 2 similar functions to work the same way, they simply changed the
PATINDEX function. It wasn't even a documented change. That was a long time
ago, but I still remember very well what happened to my code. Just a small
example of many - and has nothing to do with ANSI compliance.
A more recent example was a *feature* introduced in release 7. Somebody
decided that the ARITHABORT command was really only to be taken seriously
for SELECT statements and should be ignored for INSERT and UPDATE
statements. This was also (initially) an undocumented feature. This really
wasn't very nice for those of us who process million row inserts at night
which include arithmetic calculations on some of the columns. Microsoft
refused to fix this until SQL 2000. That one *feature* alone made 7.0 an
unusable product for us.
[color=blue][color=green]
>>the keyword is ANSI. Microsoft wanted their product to adhere more to ANSI[/color][/color]
standards<<
Erland, that is Microsoft's line and the excuse they use every time they
deliberately break something. The bottom line here is they are very
selective about WHICH ANSI rules they choose to implement and which they
conveniently ignore. If you don't believe it, call up your friends on the
development team and remind them that FROM clauses are illegal in UPDATE and
DELETE statements and they really shouldn't allow this non-ANSI behavior in
their product. Be sure to report back what they say.
[color=blue][color=green]
>>...when you port from other products...<<[/color][/color]
This is my favorite. How many products have stored procedures written in
TSQL? OK, SYBASE at least started out the same - but that was a long time
ago. When's the last time you tried to port a SYBASE stored procedure into
SQL Server? Oracle? Anybody? When's the last time you tried to port a SQL
Server stored procedure to any other database? I just love hearing about
portability!
Erland, there's nothing wrong with enhancements. Add all the features you
want but don't break my old code in the process. And don't tell me that
everything you do is to improve ANSI compliance. It's true sometimes, but
ONLY sometimes.
Microsoft simply has a terrible track record when it comes to backward
compatibility. I've been burned so many times you'll never convince me
otherwise.
In any case, what started this whole discussion was a query example that
only worked with defaults configured a particular way. I maintain that if
you code that way you will eventually be punished by Microsoft for trusting
them. It happens with almost every new release.
Richard
"Erland Sommarskog" <esquel@sommars kog.se> wrote in message
news:Xns951FF02 0B5D10Yazorman@ 127.0.0.1...[color=blue]
> Richard Romley (richardromley@ optonline.net) writes:[color=green]
> > Hmmm. Where have I heard that before? There is ALWAYS a good reason to
> > change defaults. There is ALWAYS a good reason to change the behavior of
> > existing code. Well, there is also one very good reason NOT to - doing[/color][/color]
so[color=blue][color=green]
> > breaks all the code that's been written since the beginning of time that
> > depended on the old rules.[/color]
>
> If the product does absolutely silly things, you don't have no choice. For
> instance in SQL Server 4.x you could say:
>
> SELECT a, b, COUNT(*)
> FROM tbl
> GROUP BY a
>
> Both Sybase and Microsoft outlawed this syntax in System 10 and SQL
> Server 6 respectively.
>
> For the issues we discuss, the keyword is ANSI. Microsoft wanted their
> product to adhere more to ANSI standards, and this certainly applies
> to existing code, to wit when you port from other products. However,
> MS did not go all the way. If you say SET ANSI_DEFAULTS ON, there are
> a couple of settings which are set, and I will add ARITHABORT and
> CONCAT_NULL_YIE LDS_NULL to these.
>
> ANSI_NULL_DLFT_ ON - this setting controls what happens if you create
> a column in a table without specify explicit nullability. Since none
> of NOT NULL or NULL is obvious, good practice is always state this
> explicitly.
>
> ANSI_PADDING - this column affects how trailing spaces are saved for
> varchar values. It is not likely to affect that many appliactions.
>
> ANSI_WARNINGS - the most important effect is that you get an error if
> you try to store a value that does not fir into a char/binary column.
> It does affect some application, but there is no dramatic issue. The
> other things caused by ANSI_WARNINGS is likely to have even lower impact.
>
> ARITHABORT - Few would probably complain that their division with zero
> yields an error (this also comes with ANSI_WARNINGS). Most probably
> find it a good thing.
>
> QUOTED_IDENTIFI ER - Now, here is one that with a huge impact, since
> strings quoted by " suddenly became identifiers. Mitigating, though, is
> that this can be fixed mechanically.
>
> ANSI_NULLS - This is an setting that should have absolutely no effect on
> properly written code. @x = NULL was wrong in 4.x days, it has always
> been wrong, it was just that Sybase out of folly handled NULL as equal
> to NULL. But of course, a system where the programmers did not have
> understanding of NULL values takes a serious toll here. But as I said
> the Best Practice Analyzer can help you out here.
>
> CONCAT_NULL_YIE LDS_NULL - Exactly the same thing applies here: on a
> properly implemented system, this is not an issue.
>
> ............... .....
>
> IMPLICIT_TRANSA CTIONS - Now here is one! This option is OFF by default,
> and had MS made this the default, about every application out there would
> have succumbed. Right or wrong, auto-commit has always been the way Sybase
> and SQL Server has gone.
>
> CURSOR_CLOSE_ON _COMMIT - This option is OFF by default as well. Since
> cursors are something you should not use anyway, it should have less
> impact. But the whole idea sounds corny to me. I might have a transaction
> for each iteration in the cursor. Certainly I don't want it close.
>
> So Microsoft acted judiciously when they decided what should be on by
> default and what should not. ANSI_NULLS and CONCAT_NULL_YIE LDS_NULL
> may have a great impact your code, but let me again stress that the
> original defaults were just plain wrong and indefensible to have in
> an engine to aspire to be an enterprise DBMS.
>[color=green]
> > Microsoft has proven time and time again that they simply don't give a
> > damn about the harm they inflict on their customers every time they do
> > that.[/color]
>
> Since I have good contacts with the SQL Server team, I can assure you
> that they are very anxious about compability. Very anxious.
>
> But if you have ever worked with product development, you also know that
> sometimes maintaining old functionality can be a true burden. (If you
> work for a site where you only have one production environment, this is
> not an issue for you. You can rip things out as you please.)
>
>
>
> --
> Erland Sommarskog, SQL Server MVP, esquel@sommarsk og.se
>
> Books Online for SQL Server SP3 at
> http://www.microsoft.com/sql/techinf...2000/books.asp[/color]
Comment