过程:表点击右按键,编写脚本为,create到,新查询编辑器窗口
--创建表begin
USE [tagen_020test] ----更换为新的数据库名字即可
GO
/****** Object: Table [dbo].[Park_JparkCodes] Script Date: 2017/11/29 11:44:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Park_JparkCodes](
[jparkId] [int] IDENTITY(1,1) NOT NULL,
[propertyId] [int] NULL,
[propertyNo] [nvarchar](50) NULL,
[jparkName] [nvarchar](50) NULL,
[remark] [nvarchar](50) NULL,
[parkCode] [nvarchar](50) NULL,
[parkName] [nvarchar](50) NULL,
[jparkCode] [nvarchar](50) NULL,
[addTime] [datetime] NULL,
[updateTime] [datetime] NULL,
[status] [int] NULL,
CONSTRAINT [PK_Park_JparkCodes] PRIMARY KEY CLUSTERED
(
[jparkId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
---创建表end
--插入数据begin
INSERT INTO [melife].[dbo].[Park_JparkCodes]
([propertyId]
,[propertyNo]
,[jparkName]
,[remark]
,[parkCode]
,[parkName]
,[jparkCode]
,[addTime]
,[updateTime]
,[status]) ------注意这里没有values哦
select
propertyId
,propertyNo
,jparkName
,remark
,parkCode
,parkName
,jparkCode
,addTime
,updateTime
,[status]
FROM [tagen_020test].[dbo].[Park_JparkCodes]
--插入数据end
更新一个表的字段到另一个表里
update a set a.PaidTime= m.PaidTime from t_WorkOrder AS a ,
(SELECT tw.WorkOrderNo ,tw.WorkOrderNoort,mz.PayTime,CONVERT(varchar(19),mz.PayTime,120) as PaidTime FROM t_WorkOrder tw left join [mzs_OrderConsume] mz on tw.WorkOrderNoort=mz.Partner_trade_no where tw.WorkOrderNo in(
select distinct WorkOrderNo from t_WorkOrder where AddTime >='2019-06-25 00:00:00' and AddTime<='2019-07-26 00:00:00' and WorkOrderType=1 --and PropertyId=104
and Status
>=6 and Status<=10 and PaidTime is null
)
AND mz.PayTime is not null) as m WHERE a.WorkOrderNoort=m.WorkOrderNoort