How to attach AdventureWorks 2012 to SQL Server

Have you ever wanted to install the sample database (AdventureWorks )provided by Microsoft which a lot of the tutorials and books refer to? Well one of my colleagues has started to learn SQL Server so I thought I would knock up a quick guide for him. The correct classical way is to use T-SQL would […]

Change a database state in SQL

Have you ever wanted to change a databases state from read only to read write or vice versa? Well I am going to show you how using some easy to remember T-SQL which you will be using repeatedly over time.   We received a database from a client the other day and noticed one of […]

List SQL databases in SQL Server

Have you ever wanted to list out all the databases you have on a server? Well I am going to show you how to do it quickly and easily. The other day I had completed a migration from a creaky old dinosaur server to a brand new powerful server which always brings a smile on […]

Find todays date & time in SQL Server part 2

Have you ever wanted to return the time found in GETDATE or CURRENT_TIMESTAMP to a higher level off accuracy in SQL? Well I am going to show you how. The other day I needed to get the current time to greater accuracy due to the time stamp given to some records and I had to […]

Have you ever wanted to convert a US date to UK format using SQL?

Have you ever come across the situation where you have data in US format and need it changed to UK format? Well I am going to show you how to use SQL to easily reformat the date. I have had this problem several times in the past dealing with international clients who supply databases with […]

Find the current day, month and year in SQL Server

Have you ever wanted to return the value of the current day? Month? Or year? Well its easy in SQL and I am going to show you how. The query for the current day is below. SELECT DAY(GETDATE()) The query for the current month is below. SELECT MONTH(GETDATE()) The query for the current year is […]

Find todays date and time in SQL Server

Have you ever wondered how to get the current time and date within SQL Server? Well I am going to show you two easy methods of getting this information. The first method is my preferred method as it’s slightly shorter than the second method. SELECT GETDATE() SELECT CURRENT_TIMESTAMP

Use SQL to search a column for a range of values

Have you ever wanted to search for a column for a range of values? For example if you were searching for Product ID which ranges from 1 to 300, or look for a range of names starting A to D. Well I can show you how to do these quickly and easily by using the […]

Search for a list of values using the IN command in SQL

Have you ever been presented with a list of values which need to be found in a column or wondered how to search for a list of exact names, addresses, numbers without using wildcard searches or ranges. Well SQL has the answer and it is the IN command. The above query produces 16 rows of […]

NULL Values – How to filter out NULLS and how to find NULLS using SQL

Have you ever wanted to find a NULL value or filter out NULL values within a column? Well SQL has the solution and our saviour is the ‘IS NULL’ and ‘IS NOT NULL’ commands. Using them in a ‘WHERE’ clause will allow us to do the filtering out appropriately. The above query bring us a […]

%d bloggers like this: