Sql存储过程代码优化

xkyounet xkyounet 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
请大家看看,我下面这个过程还能优化吗(简洁和效率)?

USE [price]
GO
/****** Object: StoredProcedure [dbo].[getprice] Script Date: 01/19/2012 18:04:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[getprice]
@DT nvarchar(20),@PM nvarchar(20),@GG int,@CZ int,@CD int
AS
BEGIN
SET NOCOUNT ON;

declare @pri1 int
declare @pri2 float
declare @pri3 float
declare @pri4 float
declare @price float
set @price=0
select @pri1=AVG(CONVERT(int , JG )) from [price].[dbo].[v_Price] where PM=@PM and GG=@GG and CZ=@CZ and CD=@CD and DT=@DT
select @pri2=AVG(CONVERT(float , JG )) from [price].[dbo].[v_Price] where PM=@PM and GG=@GG and CZ=@CZ and CD=@CD and DATEDIFF(MM, CONVERT(datetime, @DT, 120 ),DT)=1
select @pri3=AVG(CONVERT(float , JG )) from [price].[dbo].[v_Price] where PM=@PM and GG=@GG and CZ=@CZ and CD=@CD and DATEDIFF(MM, CONVERT(datetime, @DT, 120 ),DT)=2
select @pri4=AVG(CONVERT(float , JG )) from [price].[dbo].[v_Price] where PM=@PM and GG=@GG and CZ=@CZ and CD=@CD and DATEDIFF(MM, CONVERT(datetime, @DT, 120 ),DT)=3

if @pri1>=@pri2 set @price=@pri2 else set @price=@pri1
if @pri3<=@price set @price=@pri3
if @pri4<=@price set @price=@pri4

select @price as RE


END
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
xkyounet
疑难问题 22,298 成员 121,727 内容