SELECT columns using the LIKE keyword

Using the WHERE clause to return on the records in the Employee table where the employees are a manager of some type. This example uses the % character for any number of characters. Using the LIKE keyword to return records from the Person table where users’ first names end in “ary”. This example uses the _ characters to represent a single character. Using the LIKE keyword to return records from the Person table where users’ first names end in…

Read More

Selecting Domain from Email Address

Recently I came across a quick need where I needed to retrieve domain of the email address. The email address is in the database table. I quickly wrote following script which will extract the domain and will also count how many email addresses are there with the same domain address.

Read More

Microsoft SQL Insert Trigger to Get Current Datetime Value

This script gets the datetime value in this format MM/DD/YYYY:HR:MI:SSPM or AM. I could have used the CAST or CONVERT option but the did not reproduce the result that I wanted.  There are some option in CONVERT option but they converts into a 24hr format. Here is my trigger for insert event. USE dwdata GO /* —————————————————————————– www.myw0.com, Version 1.0, Creation Date: 11/05/2014 Functionality: Generate Datetime values into a text field —————————————————————————– */ if exists (select * from sysobjects…

Read More

Determing SQL Server Table Size within a Database

A common problem that I have recently encountered was trying to identity which table within a database was the biggest one (in record size), therefore, taking up the most physical storage space. I found and modify this store procedure to work with MSSQL 2000, MSSQL 2005, and MSSQL 2008  that will perform all needed data calls and will return a result set with the data on all tables. T-SQL Code:   USE DWDATA GO CREATE PROCEDURE GetAllTableSizes AS /* Obtains spaced used data for ALL user tables in the database */…

Read More