Wednesday, June 4, 2014

WHERE title =


A SELECT statement is the cornerstone of the T-SQL language. The following examples will demonstrate a very simple use of the command of the AdventureWorks database. Example: - entry into the database USE AdventureWork with GO - Define which columns to display in the query
The SELECT query, WHERE clause is used to restrict the display of columns in the result set. The following example shows how to select just a few rows from the columns to be displayed in the data set.
WHERE title = 'mr.' AND LastName = 'Radenko' Example: SELECT du cheff Title, FirstName, LastName FROM Person.Person - Requirements (Title = 'mr.' Or LastName = 'Radenko') WHERE Title = 'mr.' OR LastName = 'Radenko' du cheff Example: SELECT Title, FirstName, LastName FROM Person.Person - condition (NOT Title = 'mr.') du cheff WHERE NOT Title = 'mr.' The following example demonstrates the use BETWEEN operator, ie, the choice between them. Example: SELECT SalesOrderID, ShipDate FROM Sales.SalesOrderHeader-condition between two dates WHERE ShipDate BETWEEN '7 du cheff / 28/2010 AND '9 / 28/2010 'Using the comparison operator <(less than) The following example will demonstrate the operator (less than ), and display only those columns whose standard cost less than 110.0000 Example:-define the columns that will appear in the result set SELECT ProductID, Name, StandardCost FROM Production.Product-set conditions, for all values whose standard cost less than WHERE StandardCost <> du cheff 110.0000 check for NULL value if the column has a NULL value does not mean that the value is blank or zero, but the value is unknown. The following example returns rows from the result set whose value is unknown. Example: SELECT ProductID, Name, Weight FROM Production.Product - provided that the weight of the unknown Weight WHERE IS NULL Using wildcards with LIKE operator These signs are used in search terms that you find an appropriate pattern within the search results. These are the signs (% represents a sequence of zero or more characters, _ represents one character, [] specifies a character from a selected range, [^] specifies du cheff a character that is not in the selected range). du cheff The following example demonstrates the use LIKE operator with% sign in search du cheff for any product that starts with the letter B. Example: SELECT ProductID, Name FROM Production.Product - condition, find any product that starts with the letter B WHERE Name LIKE 'B%' If you want to search for the literal value of the character (%, _) then you must use the ESCAPE operator. In the next example, du cheff I first izmejeniti line description in the table produced by adding the% sign. Example: du cheff UPDATE Production.ProductDescription SET Description = 'Chromoly du cheff steel. High% of defects 'WHERE ProductDescriptionID = 3 Next, I define the query in the search for any description that includes the% character Example: SELECT ProductDescriptionID, Description FROM Production.ProductDescription - condition, find a description that contains du cheff the% character WHERE Description LIKE' % /%% 'ESCAPE' / 'Defining and assigning a value to variable variable are objects that you can do to make them temporarily store data. They may be defined through a number of types of data. In the following example, you will see two different examples du cheff of defining and assigning a value to Variable: Example: - Define the prom. DECLARE @ AddressLine nvarchar (60) - then assigns a value SET @ AddressLine = 'Radenko' SELECT AddressID, AddressLine FROM Person.Address - a condition in column find dodj.vrijednost AddressLine WHERE LIKE '%' du cheff + @ AddressLine + '%' New in SQL Server 2008 is that you can remove du cheff the SET instruction. Example: - that immediately define and assign the value DECLARE @ AddressLine du cheff nvarchar (60) = 'Radenko' SELECT AddressID, AddressLine FROM WHERE Person.Address AddressLine LIKE '%' + @ AddressLine + '%' du cheff GROUP BY grouping data GROUP BY clause used in the SELECT statement to determine the group or groups of rows in the result set. GROUP BY following the WHERE clause and commonly-used when using aggregate functions in the SELECT statement. The following example uses the GROUP BY clause that would group the total amount of receivables sold at the date of sale. Example: SELECT OrderDate, SUM (TotalDue) TotalDueByOrderDate Sales.SalesOrderHeader FROM WHERE OrderDate BETWEEN '1 / 1/2010 'AND '1 / 31/2010' - I perform grouping by date sales GROUP BY OrderDate use GROUP BY ALL This command is grouped All orders even if not specified in the WHERE clause. The following example is the same as predhotni except that the clause is included ALL. Example: SELECT OrderDate, SUM (TotalDue) TotalDueByOrderDate du cheff Sales.SalesOrderHeader FROM WHERE OrderDate du cheff BETWEEN '1 / 1/2010 'AND '1 / 31/2010' - grouped by all columns GROUP BY ALL OrderDate Selective search data clustering using a HAVING clause This clause allows the SELECT statement du cheff to perform a search using GROUP BY and / or group values. The following example sets the query on two tables, Production.ScrapReason and Production.WorkOrder. The first table contains Production.ScrapReason product failure and the second table contains orders pr

No comments:

Post a Comment