What is a literal SELECT Statement?

A literal SELECT statement does not query a table. Instead, it returns the result of a string or expression. The classic programming example of this concept would be to try and return the string “Hello World” to the results section:

SELECT ‘Hello World’

By executing this query, you will notice that “Hello World” returns to your results. It is important to note that T-SQL uses single quotes to indicate a string of text. Be careful of this as other SQL variants and other programming languages use the double quote method to indicate strings.

We can return numbers and the results of mathematical expressions using literal SELECT statements as well. If we wanted to return the number 5 to our results section, we can execute the query:

SELECT 5

If we wanted to return the result of 5 multiplied by 3:

SELECT 5*3

Or, to return the result of adding 2 to 7:

SELECT 7 + 2

While literal SELECT statements are not the most complicated type of SQL query by any standard, they can be used in conjunction with more complicated queries later on. Learning these simple queries are a great starting point for SQL beginners and act as a way for you to become comfortable with the SQL Server Management Studio (SSMS) interface.

SQL Series

As part of our goal to continue to educate our visitors on all things business intelligence, we will be releasing articles that teach basic SQL skills. These posts are great for beginners or for those looking to freshen up on their SQL. We have provided a similar series in the past when we discussed some basic SSIS and SSRS skills.

We always appreciate your comments and would love to get your feedback. Feel free to send any questions or comments to brewster@knowlton-group.com or leave a comment below!

What is SQL?

SQL stands for “structured query language”. It is the primary language responsible for managing data and data structures contained within a relational database management system (RDBMS). Adopted as a standard by the American National Standards Institute (ANSI) in 1986, it has undergone various ANSI standard modifications throughout the years as revisions are made.

Why are there different types of SQL like PLSQL, T-SQL, and MySQL?

Most RDBMS use slightly different versions of SQL. The vast majority are based on an ANSI standard of SQL, however each has their own modifications unique to their database system. For example, T-SQL contains functions like CAST() that are not a part of the ANSI standard syntax. Most of these language variations contain the ability to complete standard programming language operations like WHILE loops, if-then statements, and other classic programming operations. ANSI standard SQL limits itself to operations pertaining to querying and maintaining the data – not some of the other full-fledge programming features. If you learn one variation of the language, it should only require subtle modifications to your code for you to be able to complete queries in another variant of the language.

What type of SQL does LearnMicrosoftSQL.com use?

We will be using T-SQL for all practice problems and examples. Microsoft SQL Server is the most well-positioned RDBMS on the market given the its vast feature set and great value. Most small to medium sized organizations have Microsoft SQL Server installations; this site targets the many individuals that can benefit from learning the T-SQL variation of the language.

Can I download Microsoft SQL Server for free?

Yes! Microsoft has a free version of their database system which you can download at http://www.microsoft.com/en-us/download/details.aspx?id=29062. Make sure to download the version with SQL Server Management Studio included. By clicking the expand toggle button next to “Details”, you can ensure you download the correct version of the RDBMS. Once you have everything installed, you can navigate to http://msftdbprodsamples.codeplex.com/releases/view/55330 to download the “AdventureWorks2012” sample database. Many of the examples throughout this site will use this sample database.