Microsoft® SQL Server™ 2008 All-In-One Desk Reference For Dummies®
by Robert D. Schneider, Darril Gibson
III.3.2. Editing Your Query
You can modify any query that you create. If you're like most people, you probably won't get your query perfect the first time you try. Instead, the process involves a lot of editing — one of the reasons why the View Designer (the Query Designer accessible from the Views container) is so valuable.
Queries created in the View Designer can be tweaked (and ran) as many times as you like until it's exactly how you want. After you're happy with the results, copy your query and paste it into the query window.
Modifying queries within the query window is also possible. For example, say you create the following query by using the Query Designer from the query window. The query provides a listing of names and titles for all employees in AdventureWorks2008.
SELECT Person.Person.FirstName, Person.Person.LastName,
Person.Person.Title
FROM HumanResources.Employee INNER JOIN
Person.Person ON
HumanResources.Employee.BusinessEntityID =
Person.Person.BusinessEntityID
However, now the boss has asked you to include job titles. To do this, you could return to the Query Designer and re-create the entire query from scratch. However, being familiar with the database, you know that the JobTitle column is in the HumanResources table. You can add that column to the column list. You also have to add a comma after the Person.Person.Title column.
SELECT Person.Person.FirstName, Person.Person.LastName, Person.Person.Title, HumanResources.Employee.JobTitle FROM HumanResources.Employee ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access