Minggu, 15 Februari 2009

Microsoft SharePoint Team Blog
The official blog of the Microsoft SharePoint Product Group
Fundamentals of Creating Views

Practical Learning: Saving a View



To save the view, on the Standard toolbar, click the Save button
Set the Name to Homes and click OK

Close the view window
In the Object Explorer, under RealEstate2, right-click Views and click New View
In the Add Table dialog box, double-click PropertyTypes, Properties, and Conditions
Click Close
From the PropertyTypes table, drag PropertyTypeID and drop it on the PropertyTypeID field of the Properties table
From the Conditions table, drag ConditionID and drop it on the ConditionID field of the Properties table
On the tables, select the following fields: PropertyNumber, PropertyType, Condition, City, ZIPCode, Bedrooms, Bathrooms, and MarketValue
In the Criteria section, click PropertyType. Press Tab 3 times and press the Space bar to remove the check mark of its Output field
Press Tab 3 times. In its Filter field, type Condominiums and press Enter
On the main menu, click File -> Save
Set the Name to Condos and click OK
Close the view window

With Transact-SQL



To programmatically create a view, you use the following SQL syntax:

CREATE VIEW ViewName
AS
SELECT Statement
Microsoft SQL Server can generate skeleton code of a view for you. To use it, first create an empty query window. Display the Template Explorer. In the Template Explorer, expand the View node. From the View node, drag Create View and drop it in the query window.

The creation of a view starts with the CREATE VIEW expression followed by a name. The name of a view follows the rules and suggestions we reviewed above. After the name of the view, use the AS keyword to indicate that you are ready to define the view.

Because a view is primarily a SQL statement, it is defined using a SELECT statement, using the same rules we studied for data analysis. Here is an example of a view:

CREATE VIEW dbo.ListOfMen
AS
SELECT dbo.Genders.Gender,
dbo.Persons.FirstName, dbo.Persons.LastName
FROM dbo.Genders INNER JOIN dbo.Persons
ON dbo.Genders.GenderID = dbo.Persons.GenderID
WHERE (dbo.Genders.Gender = 'Male');
GO
After creating the SQL statement that defines the view, you must execute the statement. If using a query window, you can do this by pressing F5. Once the statement is executed, its name is automatically added to the Views node of its database even if you don't save its code.

Practical Learning: Creating a View



Make sure you have the Yugo National Bank database created in the Lesson13. If you didn't create it, do it now.
In the Object Explorer, right-click YugoNationalBank and click New Query
To create a new view, type the following code
Use YugoNationalBank;
GO
CREATE VIEW PayrollPreparation
AS
SELECT dbo.Employees.EmployeeNumber,
dbo.Employees.LastName + ', ' +
dbo.Employees.FirstName AS [Full Name],
dbo.Employees.HourlySalary,
dbo.TimeSheets.TimeSheetCode, dbo.TimeSheets.Week1Monday,
dbo.TimeSheets.Week1Tuesday, dbo.TimeSheets.Week1Wednesday,
dbo.TimeSheets.Week1Thursday, dbo.TimeSheets.Week1Friday,
dbo.TimeSheets.Week1Saturday, dbo.TimeSheets.Week1Sunday,
dbo.TimeSheets.Week2Monday, dbo.TimeSheets.Week2Tuesday,
dbo.TimeSheets.Week2Wednesday, dbo.TimeSheets.Week2Thursday,
dbo.TimeSheets.Week2Friday, dbo.TimeSheets.Week2Saturday,
dbo.TimeSheets.Week2Sunday

FROM dbo.Employees INNER JOIN dbo.TimeSheets
ON dbo.Employees.EmployeeNumber = dbo.TimeSheets.EmplNumber;
GO


To execute the code, press F5
Delete the content of the whole view window






source : http://blogs.msdn.com/sharepoint/default.aspx