欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

SQL server脚本语句积累

程序员文章站 2022-07-02 16:59:48
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. ......

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%'