Cade Bryant


Technical Article

View all settings for all databases on your server

My stored procedure, sp_dbsettings, allows you to view, in a cross-tabular format, all the common options and their values for all the databases on your server.  Optionally, you can pass a database name as an argument if you just want to view the settings for one database (i.e., EXEC sp_dbsettings 'Northwind').  Otherwise it shows info […]

You rated this post out of 5. Change rating

2002-10-09

636 reads

Technical Article

Find the Nth Occurrence of a Character in a String

T-SQL's CHARINDEX() function is a useful for parsing out characters within a string.  However, it only returns the first occurrence of a character.  Oftentimes one needs to locate the Nth instance of a character or a space, which can be a complicated task in standard T-SQL.  This function I wrote, imaginatively named CHARINDEX2(), allows one […]

4.64 (11)

You rated this post out of 5. Change rating

2002-09-27

31,363 reads

Technical Article

Stored procedure sp_for

The sp_for procedure provides simple single-statement loop processing for T-SQL statements, similar to the FOR command in the C language or the DOS command-line utility by the same name.It's syntax is similar to that of the DOS command.  It takes an argument to represent a variable, initialize the variable, set an increment, set an end […]

You rated this post out of 5. Change rating

2002-09-13

898 reads

Technical Article

FASTCOUNT() User-Defined Function (SQL 2000 only)

SQL Server's COUNT() function is a slow and expensive way to count a table's rows because it scans the entire table or index.  FASTCOUNT(), which I created, is much more efficient for this purpose - its only drawback being that it may return inaccurate results if a nonlogged (e.g., bulk) data modification operation was recently […]

You rated this post out of 5. Change rating

2002-09-10

840 reads

Technical Article

Using UDFs to avoid cursors

Let's say you have 2 tables: a Contacts table and a PhoneNumbers table (which stores all the phone numbers for each contact).  You are asked to write a query that returns each contact's name and a comma-delimited string of phone numbers for each contact, something like this:FirstName    LastName   PhoneNumbers---------    --------   --------------------------John      […]

You rated this post out of 5. Change rating

2002-07-22

998 reads

Technical Article

Preventing accidental overwrites with update SPs

Say you wanted to create an SP for updating records in a database.  How would you do this in such a way as to allow your users to edit only a subset of fields in the record, without overwriting the other fields, and without requiring verbose IF blocks and CASE statements in your code?Simple.  Use […]

You rated this post out of 5. Change rating

2002-04-16

198 reads

Blogs

AI Step 1

By

As this is an Artificial Intelligence (AI) World, things are changing. We can see that...

Beginner’s Guide: Building a Dockerized Todo App with React, Chakra UI, and Rust for Backend

By

In a containerized app, React and Chakra UI provide a robust and accessible user...

A New Word: Nachlophobia

By

nachlophobia – n. the fear that your deepest connections with people are ultimately pretty...

Read the latest Blogs

Forums

Call dynamic sql storedprocedure from SSIS execute sql task

By komal145

hi, I have a table called Rules Create table Rules ( Id int ,...

Migrating database with many orphan users.

By JasonO

I am currently upgrading a very old database running SQL Server 2008 to SQL...

Active and Active Cluster

By shiv-356842

Hi Team, I am planning to apply security updates for SQL Server 2016 on...

Visit the forum

Question of the Day

The Funny SELECTs

What is returned from this query?

SELECT
  ( SELECT COUNT (*) FROM Sales.SalesOrderHeader AS soh
    WHERE soh.OrderDate >= '01/01/2011' AND soh.OrderDate < '01/01/2012') AS OrdersIn2011
, ( SELECT COUNT (*) FROM Sales.SalesOrderHeader AS soh
    WHERE soh.OrderDate >= '01/01/2012' AND soh.OrderDate < '01/01/2013') AS OrdersIn2012
, ( SELECT COUNT (*) FROM Sales.SalesOrderHeader AS soh
    WHERE soh.OrderDate >= '01/01/2013' AND soh.OrderDate < '01/01/2014') AS OrdersIn2013;

See possible answers