You can use the TSQL DATEPART function to extract individual parts of the date from a date or time item. For instance: Will return the following output:   The second parameter is the date/time element which can be any of these types: time, date, smalldatetime, datetime, datetime2, or datetimeoffset.   Lets take a look at the possible options for the first …

The TSQL DATEPART Function Read more »

A cursor is a tool in SQL Server that allows a user to traverse through the rows of a result set one row at a time. This can be useful for performing operations on each row of the result set individually, such as updating or deleting specific rows. Cursors are created using the DECLARE CURSOR statement, and are associated with …

Simple Introduction to TSQL Cursors Read more »

On Thursday March 19th at 9:00am (pacific time), we will be hosting another free training provided by Aaron Buma and I to prepare for the Microsoft 70-461 SQL Queries exam. This week we will be a three part session on functions. This is provided free of charge to give back to the SQL community. We have been getting quite a following so …

Next Weekly Training: Functions (Logical Functions, Time Functions, and UDFs) Read more »

Here is the outline: Using Cursors Using String Functions Here is the link to the Google On Air Broadcast where you can watch for free. https://plus.google.com/events/ci8jms67qttuteegimrf4sj70sk After the presentation, I will update this page with a link to the YouTube video. This session will be about 90 minutes, Aaron Buma will present about half and I will present the other …

Today’s Live Training: Using Cursors and TSQL String Functions Read more »

First lets take a look at two queries using CURSORS, the first one will use the FORWARD_ONLY type cursor, and the second will use the FAST_FORWARD type cursor. These two types sound very similar, but perform quite differently. Now for the FAST_FORWARD CURSOR example. Notice only one line has changed, that’s the line that says “SET @PeoplePhoneCursor = CURSOR FAST_FORWARD …

Simple Cursor Example : FORWARD_ONLY vs FAST FORWARD Read more »

Earlier in the week I added a blog entry on using the OUTPUT Clause on INSERT Statements, today I will expand it by exploring the use of the OUTPUT clause with UPDATE statements. Generally when you do an UPDATE statement you only get a row count returned, you don’t generally get a result set showing what was changed. With the OUTPUT clause …

TSQL OUTPUT Clause With UPDATE Statements Read more »

NTILE is a SQL Server function that can be called in a TSQL Query. This is part of the free sql query training to prepare for the Microsoft 70-461 queries exam. Here is a video presentation on using the TSQL NTILE function. And here is the sample code associated with the presentation. Feel free to copy and paste to SSMS …

TSQL Queries – Using NTILE Read more »

The SQL Training was a lot of fun this week we covered Top, Ranking, NTILE, and Analytic functions in preparation for the Microsoft 70-461 exam. Next week Aaron Buma and I will be presenting Set Operators, Derived Tables and CTEs. The live session will be with Google On Air Broadcasts Thursday Feb 12th at 9:00am (pacific). This is a FREE SQL Training …

SQL Query Training – Next Week – Set Operators, Derived Tables and CTEs Read more »