Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Apress
committed
Oct 12, 2016
0 parents
commit 7a9bfb3
Showing
570 changed files
with
16,645 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
sqlcmd -S .\sqlexpress -i instnwnd.sql | ||
|
||
|
||
|
||
|
||
|
||
sqlcmd -S .\sqlexpress | ||
|
||
|
||
|
||
|
||
|
||
use northwind | ||
select count(*) from employees | ||
go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
namespace ConsoleApplication1 | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Console.WriteLine("Welcome to C# 3.0"); | ||
Console.ReadLine(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
WITH TopSales (SalesPersonID,TerritoryID,NumberOfSales) | ||
AS | ||
( | ||
SELECT SalesPersonID,TerritoryID, Count(*) | ||
FROM Sales.SalesOrderHeader | ||
GROUP BY SalesPersonID, TerritoryID | ||
) | ||
SELECT * FROM TopSales | ||
WHERE SalesPersonID IS NOT NULL | ||
ORDER BY NumSales DESC | ||
|
||
Use AdventureWorks | ||
Go | ||
Select CardType, ExpYear,count(CardType) AS 'Total Cards' | ||
from Sales.CreditCard | ||
Where ExpYear in (2006,2007) | ||
group by ExpYear,CardType | ||
order by CardType,ExpYear | ||
|
||
|
||
Use AdventureWorks | ||
Go | ||
select CardType ,[2006] as Year2006,[2007] as Year2007 | ||
from | ||
( | ||
select CardType,ExpYear | ||
from Sales.CreditCard | ||
)piv Pivot | ||
( | ||
count(ExpYear) for ExpYear in ([2006],[2007]) | ||
)as carddetail | ||
order by CardType | ||
|
||
|
||
select SalesPersonID, Bonus, | ||
ROW_NUMBER() over (order by SalesPersonID) as [RowCount] | ||
from Sales.SalesPerson | ||
|
||
select CustomerID, TerritoryID , | ||
Row_Number() over (Partition by TerritoryID | ||
order by CustomerID) as [RowCount] | ||
from Sales.Customer | ||
Where TerritoryID in (1,2)AND | ||
CustomerID Between 1 and 75 | ||
|
||
select Title + ' ' + FirstName + ' ' + LastName | ||
as "Person Name" | ||
from Person.Contact | ||
where FirstName like 'A%' and Title is not null | ||
|
||
select Title + ' ' + FirstName + ' ' + LastName | ||
as "Person Name" | ||
from Person.Contact | ||
where FirstName like 'B____a' and Title is not null | ||
|
||
|
||
select Title + ' ' + FirstName + ' ' + LastName | ||
as "Person Name" | ||
from Person.Contact | ||
where FirstName like '[A-I]__' and Title is not null | ||
|
||
select Title + ' ' + FirstName + ' ' + LastName | ||
as "Person Name" | ||
from Person.Contact | ||
where FirstName like '_[^I][a]__' and Title is not null | ||
|
||
select SalesOrderID,min(UnitPrice)as "Min", | ||
max(UnitPrice) as "Max",Sum(UnitPrice) as "Sum", | ||
Avg(UnitPrice)as "Avg" | ||
from Sales.SalesOrderDetail | ||
where SalesOrderID between 43659 and 43663 | ||
group by SalesOrderID | ||
|
||
Select count(*) as "Total Records" from Person.Contact | ||
Select count(Title)as "Not Null Titles" from Person.Contact | ||
|
||
select | ||
current_timestamp 'standard datetime', | ||
getdate() 'Transact-SQL datetime', | ||
datepart(year, getdate()) 'datepart year', | ||
year(getdate()) 'year function', | ||
datepart(hour, getdate()) 'hour | ||
|
||
select | ||
orders.orderid, | ||
orders.customerid, | ||
employees.lastname | ||
from | ||
orders inner join employees | ||
on | ||
orders.employeeid = employees.employeeid | ||
|
||
|
||
select | ||
o.orderid, | ||
o.customerid, | ||
e.lastname | ||
from | ||
orders o inner join employees e | ||
on | ||
o.employeeid = e.employeeid | ||
|
||
|
||
select | ||
o.orderid OrderID, | ||
o.customerid CustomerID, | ||
e.lastname Employee | ||
from | ||
orders o, employees e | ||
where | ||
o.employeeid = e.employeeid | ||
|
||
|
||
select | ||
o.orderid OrderID, | ||
c.companyname CustomerName, | ||
e.lastname Employee | ||
from | ||
orders o inner join employees e | ||
on o.employeeid = e.employeeid | ||
inner join customers c | ||
on o.customerid = c.customerid | ||
|
||
insert into employees | ||
( | ||
firstname, | ||
lastname | ||
) | ||
values ('Amy', 'Abrams') | ||
|
||
|
||
select | ||
e.firstname, | ||
e.lastname, | ||
o.orderid | ||
from | ||
employees e left outer join orders o | ||
on e.employeeid = o.employeeid | ||
order by 2, 1 | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
select * from employees | ||
|
||
|
||
select employeeid, firstname,lastname | ||
from employees | ||
|
||
|
||
|
||
where country = 'USA' | ||
|
||
|
||
|
||
select orderid,employeeid,customerid,orderdate,shipcountry | ||
from orders | ||
where employeeid = 5 and shipcountry in ('Brazil', 'France') | ||
order by shipcountry asc,orderdate asc | ||
|
||
|
||
|
||
select orderid,employeeid,customerid,orderdate,shipcountry | ||
into #myorder | ||
from orders | ||
|
||
|
||
select * from #myorder | ||
|
||
select orderid,employeeid,customerid,orderdate,shipcountry | ||
into #myemptyorder | ||
from orders | ||
where 0=1 | ||
|
||
|
||
select * from #myemptyorder | ||
|
||
insert into shippers( companyname, phone ) | ||
values ('GUIPundits', '+91 9820801756') | ||
|
||
|
||
|
||
update shippers | ||
set companyname = 'PearlHRSolution' | ||
where shipperid = 4 | ||
|
||
|
||
|
||
update shippers | ||
set companyname = 'PearlHRSolution', | ||
phone = '+91 9819133949' | ||
where shipperid = 4 | ||
|
||
|
||
delete from shippers | ||
where shipperid = 4 | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Data; | ||
using System.Data.SqlClient; | ||
|
||
namespace Chapter6 | ||
{ | ||
class CallSp1 | ||
{ | ||
static void Main() | ||
{ | ||
// create connection | ||
SqlConnection conn = new SqlConnection | ||
(@"server = .\sqlexpress; | ||
integrated security = true; | ||
database = northwind"); | ||
|
||
try | ||
{ | ||
// open connection | ||
conn.Open(); | ||
// create command | ||
SqlCommand cmd = conn.CreateCommand(); | ||
|
||
// specify stored procedure to execute | ||
cmd.CommandType = CommandType.StoredProcedure; | ||
cmd.CommandText = "sp_select_employees_details"; | ||
|
||
// execute command | ||
SqlDataReader rdr = cmd.ExecuteReader(); | ||
|
||
// Process the result set | ||
while (rdr.Read()) | ||
{ | ||
Console.WriteLine( | ||
"{0} {1} {2}" | ||
,rdr[0].ToString().PadRight(5) | ||
,rdr[1].ToString() | ||
,rdr[2].ToString()); | ||
} | ||
rdr.Close(); | ||
} | ||
catch (SqlException ex) | ||
{ | ||
Console.WriteLine(ex.ToString()); | ||
} | ||
finally | ||
{ | ||
conn.Close(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System; | ||
using System.Data; | ||
using System.Data.SqlClient; | ||
|
||
namespace Chapter6 | ||
{ | ||
class CallSp2 | ||
{ | ||
static void Main() | ||
{ | ||
|
||
// create connection | ||
SqlConnection conn = new SqlConnection(@" | ||
server = .\sqlexpress; | ||
integrated security = true; | ||
database = northwind | ||
"); | ||
try | ||
{ | ||
// open connection | ||
conn.Open(); | ||
|
||
// create command | ||
SqlCommand cmd = conn.CreateCommand(); | ||
|
||
// specify stored procedure to execute | ||
cmd.CommandType = CommandType.StoredProcedure; | ||
cmd.CommandText = "sp_orders_by_employeeid2"; | ||
|
||
// create input parameter | ||
SqlParameter inparm = cmd.Parameters.Add( | ||
"@employeeid", SqlDbType.Int); | ||
inparm.Direction = ParameterDirection.Input; | ||
inparm.Value = 2; | ||
|
||
// create output parameter | ||
SqlParameter ouparm = cmd.Parameters.Add( | ||
"@ordercount", SqlDbType.Int); | ||
ouparm.Direction = ParameterDirection.Output; | ||
|
||
// create return value parameter | ||
SqlParameter retval = cmd.Parameters.Add( | ||
"return_value", SqlDbType.Int); | ||
retval.Direction = ParameterDirection.ReturnValue; | ||
|
||
// execute command | ||
SqlDataReader rdr = cmd.ExecuteReader(); | ||
|
||
// Process the result set | ||
while (rdr.Read()) | ||
{ | ||
Console.WriteLine( | ||
"{0} {1}" | ||
, rdr[0].ToString().PadRight(5) | ||
, rdr[1].ToString()); | ||
} | ||
rdr.Close(); | ||
|
||
// display output parameter value | ||
Console.WriteLine( | ||
"The output parameter value is {0}" | ||
, cmd.Parameters["@ordercount"].Value); | ||
|
||
// display return value | ||
Console.WriteLine( | ||
"The return value is {0}" | ||
, cmd.Parameters["return_value"].Value); | ||
} | ||
catch (SqlException ex) | ||
{ | ||
Console.WriteLine(ex.ToString()); | ||
} | ||
finally | ||
{ | ||
conn.Close(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.