tbltime.sql
来自「< SQL Server2005程序设计>」· SQL 代码 · 共 17 行
SQL
17 行
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tblTime]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tblTime]
GO
CREATE TABLE [dbo].[tblTime] (
[TimeKey] [int] IDENTITY (1, 1) NOT NULL ,
[OrderDate] [datetime] NULL ,
[Year] [int] NULL ,
[Quarter] [int] NULL ,
[Month] [int] NULL
) ON [PRIMARY]
GO
INSERT INTO tblTime (OrderDate, [Year], [Quarter], [Month])
SELECT DISTINCT OrderDate, YEAR(OrderDate) AS [Year], { fn QUARTER(OrderDate) } AS Quarter, MONTH(OrderDate) AS [Month]
FROM dbo.Orders
ORDER BY [Year], [Quarter], [Month]
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?