Remove Multiple Spaces

I have a need to replace multiple space with a single space in varchar during a SQL statement.
 
On the web there were many solutions, but these two seemed to be the more simple ones.
 

DECLARE

@strValue VARCHAR(MAX)

SET @strValue = sf    ds     fds f fds fd sf    ds    

 
While

CharIndex(‘  ‘, @strValue)>0

    Select

@strValue = Replace(@strValue, ‘  ‘, ‘ ‘)

 

–********************************

DECLARE

@strValue VARCHAR(MAX)

SET

@strValue = ‘     sf ds fds f ds       fds         fd sf ds ‘

SELECT

LTRIM(REPLACE(REPLACE(REPLACE(@strValue,‘  ‘, ‘ ‘), ‘  ‘, ‘ ‘), ‘  ‘, ‘ ‘))

 
Resources:
 
Removing unwanted spaces within a string …
 
Squeeze Function

Entity Framework

 
Resources:
 ADO.NET Entity Framework
 
Introducing ADO.NET Entity Framework(By Julia Lerman) 
 
MSDN Quickstart (Entity Framework)
 
ADO.NET Entity Framework
 
Additional MSDN Links
The following topics enable you to learn more about the Entity Framework:
          Additional Entity Framework Resources

Provides links to conceptual topics and links to external topics and resources for building Entity Framework applications.

          Getting Started (Entity Framework)

Provide information about how to get up and running quickly using the Quickstart (Entity Framework), which shows how to create a simple Entity Framework application.

          Quickstart (Entity Framework)

Shows you how to use the Entity Data Model tools with Visual Studio 2008 to quickly create your first Entity Framework application.

          Application Scenarios (Entity Framework)

Provides task-based links to topics that match specific application scenarios, such as writing queries, binding objects to data controls, or implementing business logic.

          Entity Framework Features

Provides more detailed information on the features that compose the Entity Framework and links to topics that discuss those features.

          Entity Framework Terminology

Defines many of the terms that are introduced by the EDM and the Entity Framework and that are used in Entity Framework documentation.

          Tons of “How Do I?” Videos — Data Platform Development
 
Why use the Entity Framework
A decent blog that discusses LINQ to SQL, Tradiontal ADO.NET, and NHibernate.
 
Entity Framework Q&A
EntityClient + Entity SQL
Object Services + Entity SQL
Object Services + LINQ
 
Introducing the Entity Framework (by Shawn Wildermuth)
 
Julie Lermans Blog( author of Entity Framework)
 
 
MSDN Webcast: MSDN geekSpeak: Julie Lerman on ADO.NET (Level 200)
Julie does a great job of presenting EF.  She has a book called Programming Entity Framework, which is an O’Reilly press book, that is schedule to be released January 15, 2009.
 
dnrTV – Dan Simmons on The Entity Framework Part 1
 
dnrTV – Dan Simmons on The Entity Framework Part 2
 
LINQ to Relational Data: Who’s Who?
LINQ to SQL; LINQ to Entities
 
Entity Framework- The Crib Sheet
 
ADO.NET Entity Framework Essential Resources  October 2008
 
 

Taskbar and Task Tray Tools

For a good while I have been asking Microsoft for the ability to organize the Taskbar and also be able to minimize application to the Task Tray.  Over the past few day I decided that there must 3rd party tools available, and hopefully free.
 
I have found two great tools
Taskbar Shuffle
 
4T Tray Minimizer
Taskbar Shuffle allow you to rearrange running application in taskbar.
 
Tray Minimizer has many options, but the coolest is the ability to type shift+esc, which minimized the current application to the Task Tray.  I like to minimize application that are running that I don’t use much, but need them easily available (MP3 Player).
 
 

DOS – Batch Join SQL Files

We have all of our SQL script in source control.   Whenever I update the database I have to go through each file and run it individually.  I wanted a way to be able to run all SQL scripts.  So, I crated a DOS batch that would join all the files in a directory and add "GO" and CRLF between each script.
 
FOR %%A IN (*.SQL) DO (
 TYPE %%A >> AllSql.txt
 echo. >> AllSql.txt
 echo   GO >> AllSql.txt
 echo. >> AllSql.txt
 echo –%%A >> AllSql.txt
)
 
I was using Copy but I was getting NULLs in my resulting script, very strang.  I change the Copy to TYPE and everything seemed to work correctly
Also, echo. does CRLF
 
Resource
How to insert a carriage return with batch
 
How to write a DOS batch file to loop through files
 
 
 

Regular Expression Negative Lookahead

I have a process that creates XML and inserts data within a element.  Some of the data that is inserted includes "&"s.  Since "&" can not be inserted into the XML without causing problems, I need a process to escape "&", but I do not want "&" escaped for the following, since they have already escaped.
&, >, <, ', ",
 
This is pretty easy process with a while and indexOf, but quite slow.  I believe a RegEx could provide the same functionality, but be more efficient.   My solution uses the following negative lookahead regular expression. 
&(?!amp;)(?!gt;)(?!lt;)(?!apos;)(?!quot;)
 
 
Resources
Regular-Expressions.Info (Lookahead and Lookbehind Zero-Width Assertions)
 
!!(This did not seem to work, but it did point me in the right direction)Regex to match against something that is not a specific substring (
example of not working (&([^(&)(>)(<)(')(")])) it was close but not perfect