D. Create tables with SELECT INTO

statements
#tsql#statements

The following example uses

to prevent the retrieval of duplicate titles.

The following first example creates a temporary table named

in.

This second example creates the permanent table.

DISTINCT

#Bicycles

tempdb

NewProducts

USE
AdventureWorks2025;
GO
SELECT
'Total income is'
,
((OrderQty * UnitPrice) * (1.0 - UnitPriceDiscount)),
' for '
,
p.Name
AS
ProductName
FROM
Production.Product
AS p
INNER
JOIN
Sales.SalesOrderDetail
AS sod
ON p.ProductID = sod.ProductID
ORDER
BY
ProductName
ASC
;
GO
USE
AdventureWorks2025;
GO
SELECT
DISTINCT
JobTitle
FROM
HumanResources.Employee
ORDER
BY
JobTitle;
GO
USE tempdb;
GO
IF OBJECT_ID(N'#Bicycles', N'U') IS NOT NULL
DROP
TABLE
#Bicycles;
GO
SELECT
*
INTO
#Bicycles
FROM
AdventureWorks2025.Production.Product
WHERE
ProductNumber
LIKE
'BK%'
;
GO