Saturday, December 05, 2009

SQL Server 2008 T-SQL: Insert Multiple Rows

 

SQL Server 2008 T-SQL Insert Multiple

In SQL Server 2005, in order to insert 3 rows to a table, you had to run 3 INSERT statements:

insert into Customers (Name, City, Phone) values ('Customer #1', 'Jerusalem', '2343245')

insert into Customers (Name, City, Phone) values ('Customer #2', 'Tel Aviv', '0987345')

insert into Customers (Name, City, Phone) values ('Customer #3', 'Haifa', '275466')

In SQL Server 2008, you can insert multiple rows in a single insert statement that takes  a number of value arrays:

insert into Customers (Name, City, Phone)

values

    ('Customer #1', 'Jerusalem', '2343245'),

    ('Customer #2', 'Tel Aviv', '0987345'),

    ('Customer #3', 'Haifa', '275466')

Also nice...

SQL Server 2008 T-SQL: DECLARE and SET in the Same Statement

SQL Server 2008 T-SQL DECLARE  SET

In SQL Server 2005, if you wanted to declare a new variable and set its value, you had to write both DELCARE and SET statements:

DECLARE @City VARCHAR(20)

SET @City = 'London'

A new T-SQL improvement in SQL Server 2008 is allows you to write DECLARE and SET in the Same Statement:

DECLARE @City VARCHAR(20) = 'London'

If you try this in SQL Server 2005, you'll get the following error message:

Msg 139, Level 15, State 1, Line 0
Cannot assign a default value to a local variable.

Not a big deal, but can get our code to look better!

Enjoy!

Friday, December 04, 2009

SQL Server 2008 IntelliSense

SQL Server 2008 IntelliSense

SQL Server 2008 IntelliSence

The most trivial feature in all developer tools is Intelligence. Developers just can't live without it, and when they do, they make mistakes that cause errors at runtime.

SQL Server 2008 now supports IntelliSense that can make developers more productive while writing database applications.

For example:

when writing queries against the DB:

SQL Server 2008 IntelliSense

or when writing a script, the editor notices that the Customers table has a column called Name, but does not have a column called Citu.

SQL Server 2008 IntelliSense

Great, isn't it?

BigInteger in .NET 4.0

One of the simplest new additions to the .NET 4.0 framework is an integer with arbitrary length, System.Numerics.BigInteger. Here’s a simple usage example, comparing it to a double:

DEFINATION :  The BigInteger type is an immutable type that represents an arbitrarily large integer whose value in theory has no upper or lower bounds.

WARNING : Because the BigInteger type is immutable (see Mutability and the BigInteger Structure) and because it has no upper or lower bounds, anOutOfMemoryException can be thrown for any operation that causes a BigInteger value to grow too large.

BigInteger b = BigInteger.Pow(2, 64);

Console.WriteLine("BigInteger: {0}", b.ToString("N"));

Console.WriteLine("Double:     {0}", Math.Pow(2, 64).ToString("N"));

Console.WriteLine();

b = BigInteger.Pow(2, 128);

Console.WriteLine("BigInteger: {0}", b.ToString("N"));

Console.WriteLine("Double:     {0}", ((double)b).ToString("N"));

The output is:

image_284C9F36

.NET 4, VS 2010 and Office: New Features in .NET 4 for Office Developers

 

Now that .NET 4 and VS 2010 are out, at least in Beta, I thought it would be a good time to show off some of the new features that are applicable to Office development.  In this first screen cast I will cover something new to C# specifically, optional parameters, as well as Lambda expressions. 

See the Video on the channel 9 here.