Posts
119
Comments
115
Trackbacks
22
January 2007 Entries
SQL Server and daylight savings changes

In case you don't already know, Daylight Savings Time starts three weeks earlier and ends four weeks later this year than in previous years.  This does not affect SQL Server directly because it uses the Windows clock as its clock, but you might have some stored procedures, views, or functions that try to calculate DST based on the old dates.  If you think you might, try running the following on each of your databases.  Feel free to change the "LIKE" arguments or add "OR" clauses.

-- procedures
SELECT ROUTINE_NAME, ROUTINE_DEFINITION
    FROM INFORMATION_SCHEMA.ROUTINES
    WHERE ROUTINE_TYPE='PROCEDURE'
 AND (ROUTINE_DEFINITION LIKE '%dst%'
 OR ROUTINE_DEFINITION LIKE '%daylight%'
 OR ROUTINE_DEFINITION LIKE '%first%sunday%'
 OR ROUTINE_DEFINITION LIKE '%last%sunday%')
-- functions
SELECT ROUTINE_NAME, ROUTINE_DEFINITION
    FROM INFORMATION_SCHEMA.ROUTINES
    WHERE ROUTINE_TYPE='FUNCTION'
 AND (ROUTINE_DEFINITION LIKE '%dst%'
 OR ROUTINE_DEFINITION LIKE '%daylight%'
 OR ROUTINE_DEFINITION LIKE '%first%sunday%'
 OR ROUTINE_DEFINITION LIKE '%last%sunday%')
-- views
 SELECT table_name, view_definition
     FROM INFORMATION_SCHEMA.VIEWS
     WHERE VIEW_DEFINITION LIKE '%dst%'
 OR VIEW_DEFINITION LIKE '%daylight%'
 OR VIEW_DEFINITION LIKE '%first%sunday%'
 OR VIEW_DEFINITION LIKE '%last%sunday%'

 

Information_Schema views: http://msdn2.microsoft.com/en-us/library/ms186778.aspx

Preparing for Daylight Savings: http://www.microsoft.com/windows/timezone/dst2007.mspx

posted @ Tuesday, January 30, 2007 8:53 PM | Feedback (1)
Perific wireless mouse

So I decided a while back to get a new mouse that would ease my shoulder and hand pain, and I happened upon this.  Well I've been using it for a few weeks now on my Dell 4550 with Windows XP, and I thought I'd share my thoughts on the Perific wireless mouse for anybody considering a new mouse.

Pros

  • If your posture is good (or if you start trying harder to straighten your shoulders), it really does seem like it's good for the shoulder and whatnot.
  • It's very easy to use it in your hand rather than on a mousepad, and going from mousing to typing in this situation is a breeze.

Cons

  • It's expensive - I paid around US$120.
  • It takes a second or two to respond when you haven't used it for a while.  My old MS wireless mouse never had that problem.
  • The scroll wheel has been randomly losing its ability to scroll in a web browser.  If I switch to another Windows session (i.e. Switch User from Log Off menu in Windows XP) then switch back, the functionality returns.
  • The rechargeable batteries inside the mouse only last about a week.  The good news is that there's a charging cable in the receiver.  The bad news is that the cable is fairly short.
  • The range isn't very good.  I'm lucky if I get a good signal at 3 feet.
  • It feels like it could break at any moment because the plastic is so cheap.
posted @ Tuesday, January 30, 2007 8:12 PM | Feedback (1)
idea for McDonald's commercial
I have a fun idea for a new McDonald's commercial.  It opens with the latest jingle (bah dah bah bah bah), followed by Ronald McDonald driving his Hummer up to the edge of a rainforest.  He precedes to light the rainforest on fire, and as he watches it burn, he eats several Big Macs and throws the wrappers on the ground.  Then we cut to a fatter Ronald McDonald testifying before Congress that global warming isn't really happening.  Then we cut to an even fatter Ronald marching the cows into the slaughterhouse and cutting their throats.  We end with a gigantic Ronald, covered in blood and chowing down burgers and fries, not able to get off the couch.  Cue the jingle, and... scene.
posted @ Monday, January 29, 2007 8:39 PM | Feedback (0)
silly meteorologists (if that is your real name)
Has anybody else noticed that the weather forecast makes no logical sense sometimes?  On occasion the low for one day is higher than the high for the next day.  How can there be a gap?  The only answer is that the forecast is not for a 24-hour period, which is just weird, even though people generally don't care what the weather will be like between midnight and 5 A.M.
posted @ Thursday, January 25, 2007 10:27 PM | Feedback (0)
mssqlsystemresource

This is a great explanation of the mssqlsystemresource database in SQL Server 2005 and how to look at what's inside it even though it's hidden.

http://www.aspfaq.com/sql2005/show.asp?id=28

posted @ Thursday, January 25, 2007 4:25 PM | Feedback (0)
controversial...
I'm about to say something that many people will disagree with:  Siamese Dream, the Smashing Pumpkins album, may be the best-produced album ever.
posted @ Thursday, January 25, 2007 1:05 AM | Feedback (1)
the ideal vehicle

Here's what I want in a vehicle.  I think so many people in the United States want the same thing (or something similar) that it's ridiculous that there's nothing for sale that even approaches it.

- it should be 100% recyclable

- it should be a plug-in hybrid and get around 80-90 mpg (if possible with the previous requirement)

- it should contain airbags all over the place (along with all the other good safety features)

- it should have night vision

- it should be all-wheel drive

- it should have a navigation system with a backup camera and bluetooth phone capability

- it should be around the size of the Acura RDX, but maybe have optional third-row seating

- it should not have leather

- it should be made with quality parts whenever it takes less energy and pollutes less to create a quality part once rather than having to replace a cheap part

posted @ Monday, January 22, 2007 11:29 PM | Feedback (0)
shows to watch

If you're looking to watch some new (i.e. new to you) shows on DVD (thru Netflix or whatever), here are some recommendations:

Six Feet Under: completely original and addictive, very emotional
Lost*: riveting and original storyline, good casting, marginal dialog 
Entourage: light and funny, and a nice view of what an acting career can be like 
Weeds: funny, original 
The West Wing: smart, great acting, great dialog

* I've only seen the first season of Lost, so I can't comment on anything after that.

 

posted @ Monday, January 22, 2007 6:54 PM | Feedback (1)
It's great to be echoed...

I love this article, it echoes my thoughts from yesterday about how high gas prices are a wonderful thing (yes the article is nine months old, but I just saw it for the first time, and it's still valid):

http://www.slate.com/id/2140613/

To add to what I said, it's not just high gasoline prices that we should be hoping for, it's high ENERGY prices.  I'm sure this is obvious to most people, but I'll state it anyway: the higher the price of energy, the less people will use.  I've communicated with Jorge Carrasco, the superintendent of Seattle City Light (Seattle's electricity provider), and he claims to understand that, yet Seattle's mayor Greg Nickels continues to pat himself on the back for lowering rates, despite having a reputation as a leader in the environmental movement.  

 

posted @ Friday, January 19, 2007 11:43 PM | Feedback (2)
C# loops: Performance Iterating Generic Lists

This is a very interesting post, the important thing to take away being that using "for" rather than "foreach" seems to be noticeably faster in big lists.

http://www.thinksharp.org/?p=50

posted @ Friday, January 19, 2007 10:12 PM | Feedback (0)
The time for high gas prices is now...

Unless you don't like science (defined here as knowledge derived through observation and experimentation) and would prefer to live in the Dark Ages, it should be clear that humans can't continue polluting Earth without severe consequences.  There are several kinds of people in this world: those who believe that non-cyclic global warming is happening (whether they care or not); those who know nothing about it because they're too concerned with their own lives (rightly or wrongly); those who believe that the current warming is part of a natural cycle because that's what they were told; and those who believe that the current warming is part of a natural cycle because they (a) don't want to deal with the decrease in standard of living necessary to sustain life on Earth, or (b) have actually been convinced by a segment of data that makes things seem unclear.  Need I remind this last group that things are rarely 100% certain in science?

Now that we've established that burning fossil fuels causes an increase in carbon dioxide in the atmosphere, and that science has led probably 99% of  "experts" to believe strongly that increased carbon dioxide has resulted in global warming, why is it so hard for government representatives--especially those who call themselves environmentalists--to understand that while low gasoline prices are great for the expansion of the economy, both in the U.S. and worldwide, they may be one of the worst things possible for the human race, not to mention every other living thing on the planet?  Maybe they do understand it, but they know that if people don't have jobs, they won't re-elect incumbents.  They probably also realize, to their credit, that high gas prices hit the poor a lot harder than they hit the wealthy (even if a company goes out of business because of high petrol prices, the executives are still a lot more likely to land on their feet than those at the bottom).

posted @ Thursday, January 18, 2007 11:50 PM | Feedback (1)
What separates an expert from a guru?

The brain of an expert has been trained to access a good deal of the knowledge that he or she has attained through study and experience in his or field.  The brain of a guru can readily access almost anything about his or her field that he or she has learned, but at times can also see beyond that to find solutions that are new or unheard of.

posted @ Wednesday, January 17, 2007 6:18 PM | Feedback (0)
ListBox bug in C#?

I don't know if this would be considered a bug or not, or if I'm just missing something, but when you use ListBox.DataSource in Windows.Forms (.Net 2.0), and you add or remove an item from an ArrayList that is set as the DataSource, there is no method to refresh the listbox.  The only thing I know that works is setting the DataSource to null and then setting it back to the ArrayList.  That just doesn't seem right. 

 

addendum (the next day):  I may have found another bug!  When I move an item up or down in my ArrayList and then rebind it to the ListBox, I still want the item that was moved to be selected.  I tried ListBox.ClearSelected() followed by ListBox.SelectedIndex = originalIndex, but that resulted in both the zero-index item being selected and the original item being selected.  I ended up having to do the following line twice in a row before setting the selection:

ListBox.SelectedIndex = -1;

posted @ Wednesday, January 17, 2007 1:15 AM | Feedback (4)
new words

It's always bothered me that there's not a single word for multiples of ten and a single word for multiples of five.  It bothers me because society determined long ago that these "round" numbers were far more important than others (e.g. the 75th anniversary gets far more attention than the 74th).  To that end, I'm creating two new words.

decager: any integer containing a zero in the ones column; examples are 0, 10, -20, 250, 370

quinteger: any integer containing a zero or a five in the ones column; examples are 0, 15, -80, 250, 375

 

posted @ Tuesday, January 16, 2007 4:52 PM | Feedback (0)
missing Windows versions?
Did anybody ever figure out what happened to the 91 versions of Windows that should have been between Windows 3.0 and Windows 95?  I'm pretty sure I never saw them...
posted @ Thursday, January 11, 2007 9:46 PM | Feedback (0)
checking for RESTORE permissions with C#/SQL

In case anyone's interested, here's a line of C# that lets you check to see whether the selected user (Windows or SQL) has RESTORE permissions on a specific database.  It uses SMO, and you'll need to use System.Security.Principal to get the Windows user logged on to your application, if not using SQL authentication.  Pull out the stuff in quotes if you want to try it in Query Analyzer.  This page is helpful in understanding the RESTORE command and who should have permissions to run it.

Boolean canRestore = Convert.ToBoolean(srvr.ConnectionContext.ExecuteScalar("IF (IS_SRVROLEMEMBER ('sysadmin') = 1 ) BEGIN SELECT 1 END ELSE IF (IS_SRVROLEMEMBER ('dbcreator') = 1 ) BEGIN SELECT 1 END ELSE IF ( (SELECT COUNT(*) FROM (SELECT [name],SUSER_SNAME(sid) AS [user] FROM master..sysdatabases WHERE [name] = '" + [dbName] + "') t1 WHERE [user] = '" + [selectedUser] + "') > 0 ) BEGIN SELECT 1 END ELSE BEGIN SELECT 0 END"));

posted @ Wednesday, January 10, 2007 8:20 PM | Feedback (0)
I should be a professional proofreader...

It never ceases to amaze me how little proofreading goes on at major media outlets.  I can't remember the last time I went a full day without seeing a mistake.  Check out the sentence below from an article on both the Houston Chronicle's website and the Boston Herald's website:

"U.N. Secretary-General Ban Ki-moon is concerned that U.S. bombing in southern Somalia could escalate hostilities and harm civilians who are reported to have been killed in the airstrike, a spokeswoman said Tuesday."

http://www.chron.com/disp/story.mpl/world/4459408.html

http://news.bostonherald.com/international/view.bg?articleid=176310

 

posted @ Wednesday, January 10, 2007 3:56 PM | Feedback (0)
compatibility mode

This is an interesting post about how compatibility mode in SQL Server 2005 can really make a difference: http://mapamdug.blogspot.com/2006/03/sql-server-2005-gotcha-1.html

If anybody has run into any other gotchas or whatever related to the compatibility mode, I'd love to hear about it.  I once tried upgrading a db from 80 to 90 and got so many errors it was unbelievable, mainly because of "incorrect syntax" or "ambiguous column name" in stored procedures.

The following is from the BOL, I'm posting it here because anybody moving from SQL 2000 to 2005 should really get to know this stuff:

Behavioral Differences Between Earlier Compatibility Levels and Level 90

Compatibility level setting of 80 or earlier Compatibility level setting of 90 Possibility of impact

For locking hints in the FROM clause, the WITH keyword is always optional.

With some exceptions, table hints are supported in the FROM clause only when the hints are specified with the WITH keyword. For more information, see FROM (Transact-SQL).

High

The *= and =* operators for outer join are supported with a warning message.

These operators are not supported; the OUTER JOIN keyword should be used.

High

WHEN binding the column references in the ORDER BY list to the columns produced by the SELECT list, column ambiguities are ignored and column prefixes are sometimes ignored.

For instance, an ORDER BY expression that is made up of a single two-part column (<table_alias>.<column>) that is used as a reference to a column alias in a SELECT list is accepted, but the table alias is ignored. For example, in the query SELECT DISTINCT c1 = c1*-1 FROM t_table x ORDER BY x.c1, the ORDER BY operation does not occur on the specified source column (x.c1); instead it occurs on the c1 column that is defined in the query.

Errors are raised on column ambiguities. Column prefixes, if any, specified in ORDER BY are not ignored when binding to a column produced by the SELECT list.

Medium

The UNION of a variable-length column and a fixed length column produces a fixed-length column.

The UNION of a variable-length column and a fixed length column produces a variable-length column.

Medium

SET XACT_ABORT OFF is allowed inside a trigger.

SET XACT_ABORT OFF is not allowed inside a trigger.

Medium

The FOR BROWSE clause is allowed (and ignored) in views.

The FOR BROWSE clause is not allowed in views.

Medium

Views with CHECK OPTION are supported incorrectly if the view or a view it references contains TOP.

Views with CHECK OPTION are not supported if the view or a view it references contains TOP.

Medium

If a passthrough query against a remote data source [OpenRowset or OpenQuery] produces columns with duplicate names, the duplicate column names are ignored unless the columns are explicitly named in the query.

If a passthrough query against a remote data source [OpenRowset or OpenQuery] produces a column with duplicate column names, an error is raised.

Low

Character string constants and varbinary constants of size greater than 8000 are treated as text, ntext, or image.

Character string constants and varbinary constants of size greater than 8000 are treated as type varchar(max) (or nvarchar(max) and varbinary(max), respectively). This can change the data type of the table created using SELECT … INTO if the SELECT list contains such expressions.

Low

Comparisons between numeric types (smallint, tinyint, int, bigint, numeric, decimal, smallmoney, money) are done by converting the comparand with lower precedence in the type hierarchy to the type whose precedence is higher.

The numeric-type values are compared without conversions. This provides improved performance. However, this can cause some changes in behavior, especially in cases in which the conversion caused overflow exceptions.

Low

Built-in metadata functions that take string arguments truncate their input if the input is longer than 4000 characters.

Built-in metadata functions raise an error if the truncation would result in the loss of nonspace characters.

Low

The set of disallowed characters in an unquoted identifier remains unchanged.

The Transact-SQL parser supports the Unicode 3.2 standard, which changes the character classification for some international characters that are now not allowed in nondelimited identifiers.

Low

SET ANSI_WARNINGS ON does not override the setting of SET ARITHABORT OFF for the case of floating point domain errors [that is, negative arguments for the log() function]. If ANSI_WARNINGS is ON but ARITHABORT is OFF, floating point domain errors do not cause the query to be terminated.

SET ANSI_WARNINGS ON completely overrides ARITHABORT OFF setting. Floating point domain errors in this case will cause the query to be terminated.

Low

Non-integer constants are allowed (and ignored) in the ORDER BY clause.

Non-integer constants are not allowed in the ORDER BY clause.

Low

Empty SET statement (with no SET option assignments) is allowed.

Empty SET clause is not allowed.

Low

The IDENTITY attribute is not derived correctly for columns produced by a derived table.

The IDENTITY attribute is derived correctly for columns produced by derived tables.

Low

The nullability property of arithmetic operators over floating point data type is always nullable.

The nullability property of arithmetic operators over the floating point data type is changed to nonnullable for the case where the inputs are nonnullable and ANSI_WARNINGS is ON.

Low

In the INSERT .. SELECT statement with UNION, the types produced by the individual result sets are all converted to the destination result type.

In the INSERT .. SELECT statement with UNION, the dominant type of the various branches is determined, and the results are converted to that type before being converted to the destination table type.

Low

In the SELECT .. FOR XML statement, the hex(27) (the ' character) and hex(22) (the " character) are always entitized, even where not required.

FOR XML entitizes hex(27)and hex(22) only where required. They are not entitized in the following situations:

  • In attribute content, hex(27) (the ' character) is not entitized if attribute values are delimited with ", and hex(22) (the " character) is not entitized if attribute values are delimited with '.

  • In element content, hex(27) and hex(22) are never entitized.

Low

In FOR XML, the timestamp value is mapped to an integer.

In FOR XML, the timestamp value is mapped to an binary value.

For more information, see FOR XML Support for the timestamp Data Type.

High (if a timestamp column is used); otherwise, low

In FOR XML and OPENXML, high-range Unicode characters (3 bytes) in names are represented using 8 positions.

For example, using 8 positions, FOR XML represents the Unicode code point U+10000 as:

<a_x00010000_ c1="1" />

In FOR XML and OPENXML, high-range Unicode characters (3 bytes) in names are represented using 6 positions.

For example, using 6 positions, FOR XML represents the Unicode code point U+10000 as:

<a_x010000_ c1="1" />

Low

In FOR XML, derived table mappings in AUTO mode are treated transparently.

For example:

Copy Code
USE AdventureWorks
CREATE TABLE Test(id int);
INSERT INTO Test VALUES(1);
INSERT INTO Test VALUES(2);
SELECT * FROM (SELECT a.id AS a, 
b.id AS b FROM Test a 
JOIN Test b ON a.id=b.id) 
Test FOR XML AUTO;

When the compatibility level for AdventureWorks is set to 80, the above example produces:

<a a="1"><b b="1"/></a>

<a a="2"><b b="2"/></a>

In FOR XML, derived table mappings in AUTO mode are treated opaquely.

When the compatibility level for AdventureWorks is set to 90, the preceding example produces:

<Test a="1" b="1"/>

<Test a="2" b="2"/>

For more information about changes to AUTO mode, see AUTO Mode Enhancements.

High (if FOR XML AUTO mode is applied on views); otherwise, low

String to money conversions support using a backslash character (\) as a currency symbol only in the Japanese and Korean languages.

The backslash character (\) is accepted in all string to money conversions in all languages. ISNUMERIC would return true when \ is used as a currency symbol.

For databases on versions of SQL Server earlier than SQL Server 2005, this new behavior breaks indexes and computed columns that depend on an ISNUMERIC return value that contains \ and for which the language is neither Japanese nor Korean.

low

The result of an arithmetic operator is always nullable, even if the operands are nonnullable and ANSI_WARNINGS or ARITHABORT is set ON.

When ANSI_WARNINGS or ARITHABORT are set to ON, the result of a floating point arithmetic operator is nonnullable, if both operands are nonnullable.

This change in nullability could cause failure when bcp is used to bulk export data that uses the binary format from a SQL Server 2000 table with a computed column that uses a floating point arithmetic operator and bcp or BULK INSERT is then used bulk import that data into a SQL Server 2005 table with the same definition.

Note:
When both options are OFF, the Database Engine marks the result as nullable. This is the same as in SQL Server 2000.

low

Domain errors are not controlled by ANSI_WARNINGS. ARITHABORT settings are honored, if ANSI_WARNINGS are set to OFF and there is no change to ARITHABORT.

Domain errors are also controlled by ANSI_WARNINGS and are severity 16 errors. If either ANSI_WARNINGS or ARITHABORT are ON, an error is thrown instead of returning NULL value. User scripts that depend upon ARITHABORT being set to OFF might be broken by this change.

medium

In an INSERT SELECT from a UNION of different data types, each UNION branch is directly cast to the type of the target column of the INSERT. Even if the union used by itself could fail because of incompatible type conversions, the INSERT SELECT makes the UNION succeed because the branch to the result type of the UNION is never converted.

In SQL Server 2005, the result type of UNION is derived independently of INSERT SELECT. Each branch of UNION is cast to the result type of UNION, and then cast to the target column type of INSERT. If there are incompatible types in the UNION, the first cast might cause an error. To run in compatibility level 90, you must fix all incompatible type unions used inside INSERT SELECT.

medium

For built-in functions that take nvarchar as a parameter, if the supplied value is varchar, the value is converted to nvarchar(4000). In SQL Server 2000, if a larger value is passed, it is silently truncated.

For built-in functions that take nvarchar as a parameter, if the supplied value is varchar, the value is still converted to nvarchar(4000). However, if a larger value is passed, SQL Server 2005 generates an error.

To run in compatibility level 90, you must fix any custom code that relies on the truncation behavior.

low

A union of fixed-length (char, binary, or nchar) string with a variable-length (varchar, varbinary, nvarchar) string returns a fixed-length result.

The union of a variable-size string and a fixed-size string returns a variable-size string.

To run in compatibility level 90, you must fix all the places (indexes, queries, and computed columns) that depend on the type resulting from a union of a variable-size type and a fixed-size type.

low

Object names containing the character 0xFFFF are valid identifiers.

Object names containing the character 0xFFFF are invalid identifiers and cannot be accessed.

To run in compatibility level 90, you must rename objects that contain this character.

Low

In SELECT ISNUMERIC('<string>'), embedded commas within <string> are significant.

For example, the following SELECT ISNUMERIC('121212,12') query returns 0. This indicates that the string 121212,12 is not numeric.

In SELECT ISNUMERIC('<string>'), embedded commas within <string> are ignored.

For example, the following SELECT ISNUMERIC('121212,12') query returns 1. This indicate that the string 121212,12 is numeric.

Low

posted @ Thursday, January 04, 2007 4:15 PM | Feedback (1)
News