zoukankan      html  css  js  c++  java
  • mssql存储过程demo

    ALTER PROCEDURE [dbo].[sp_get_saleData]
    AS
    BEGIN
    set nocount on
    -- 获取最近上传数据的时间戳
    declare @dd datetime
    select @dd=LastUpload from sys_upload where UploadType='SaleData'
    -- 将要上传哪些销售单
    declare @billIds varchar(400)
    declare @billId varchar(40)
    DECLARE c1 CURSOR FOR
    select top 5 SaleNo from Pos_Master where SaleDate>@dd -- 一次上传5笔
    open c1
    FETCH NEXT FROM c1 INTO @billId
    WHILE @@FETCH_STATUS = 0
    BEGIN
    if @billIds is null begin
    set @billIds=''''+@billId+''''
    end else begin
    set @billIds=@billIds+','+''''+@billId+''''
    end
    FETCH NEXT FROM c1 INTO @billId
    end
    close c1
    deallocate c1

    declare @sql varchar(2000)
    declare @time2 datetime
    create table #tmp(
    time2 datetime
    )
    set @sql='insert into #tmp select max(SaleDate) from Pos_Master where SaleNo in ('+@billids+')'
    exec(@sql)
    select @time2=time2 from #tmp

    -- 获取要上传的销售数据
    set @sql='select b.SaleNo as billId,b.SaleDate,a.GoodsID,a.GoodsName,a.RetailPrice as price'
    +',a.Qty,a.Amount,dbo.f_GetCookType(b.saleDate) as cooktype'
    +',a.bigKindId,a.bigKindName,a.smallKindId,a.smallKindName'
    +',a.UnitCode as unitid,a.Unit as unitname,'''' as vipid,'''' as vipname,b.Employee as skyid'
    +',b.Createtor as skyname,'''' as ywyid,'''' as ywyname,'+''''
    +convert(varchar,@time2,21)+''''+' as time2'
    +' from pos_detail a'
    +' inner join Pos_Master b on a.SaleNo=b.SaleNo'
    +' where b.SaleNo in ('+@billIds+')'
    exec (@sql)

    drop table #tmp

    set nocount off
    END

  • 相关阅读:
    ESP32学习目录
    python中mysql管理模块mysql-connector使用
    MYSQL基础知识和操作
    urlib补充
    Python3中Urllib库是什么?urllib模块基本使用
    递归:斐波契那数列
    python正则模块一
    模块&包
    XML模块示例代码
    使用python操作XML增删改查
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/3809403.html
Copyright © 2011-2022 走看看