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

转载于:https://www.cnblogs.com/hnxxcxg/p/3809403.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值