SQL server脚本语句积累

1:往现有的表中增加一个字段

IF NOT EXISTS ( SELECT 1

  FROM sys.sysobjects so WITH ( NOLOCK )
  INNER JOIN sys.syscolumns sc WITH ( NOLOCK ) ON so.id = sc.id
  WHERE so.name = 'EgPurchase_OrderPlan'
  AND sc.name = 'IsNewSystem' )
  BEGIN
    ALTER TABLE dbo.EgPurchase_OrderPlan ADD IsNewSystem INT NOT NULL DEFAULT 0
    EXECUTE sp_addextendedproperty N'MS_Description', '是否推送新系统', N'user',
    N'dbo', N'table', N'EgPurchase_OrderPlan', N'column', N'IsNewSystem'
  END
GO

2:更新一个字段

UPDATE dbo.EgSys_ExportSet
SET ColumnNames='订单编号|1,店铺名称|1,仓库名称|1,平台|1,商品|1,商品名称|1,商品编号|1,规格编码|1,颜色名称|1,规格名称|1,商品数量|1,吊牌价|1,单价|1,成本价|1,成交价|1,应付金额|1,实付金额|1,优惠|1,运费|1,重量|1,交易单号|1,实付物流费用|1,快递单号|1,物流公司|1,买家昵称|1,收件人|1,国家|1,省|1,市|1,区|1,地址|1,完整地址|1,邮编|1,买家留言|1,卖家留言|1,买家手机|1,买家电话|1,买家邮箱|1,订单状态|1,订单付款时间|1,订单完结时间|1,发货日期|1,换货状态|1,换货数量|1,付款状态|1,删除状态|1,副单状态|1,退款状态|1,退款金额|1,主订单号|1,城市代码|0,订单备注|0,分销商名|0,业务员|0,国家中文|0,国家简写|0,申报费用|0,商品类别|0,商品类别(英)|0,商品备注|0,客户条形码|1,Sku状态|0,商品条形码|1'
WHERE ModuleMark='AllOrder'

3:查询EDL转运单号

SELECT d.*
FROM dbo.EgSys_Delivery d WITH ( NOLOCK )
INNER JOIN dbo.Egsys_PlatformTrade t WITH ( NOLOCK ) ON t.tid = d.tid
WHERE d.deliveryTime < CONVERT(DATE, GETDATE())
AND d.deliveryTime >= CONVERT(DATE, DATEADD(DAY, -70000, GETDATE()))
AND t.orderState >= 4
AND t.order_deleteState != 1
AND d.logisticsCompany LIKE 'EdlExpress%'
AND d.logisticsNo LIKE 'HMZX%'

posted @ 2019-01-11 21:56 万城归 阅读(...) 评论(...) 编辑 收藏