简单存储过程示例优化。。。多列取最小值
来源:互联网 发布:dll不兼容windows 编辑:程序博客网 时间:2024/06/08 12:53
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
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
- 简单存储过程示例优化。。。多列取最小值
- 简单存储过程示例
- sybase存储过程简单示例
- mysql 存储过程 简单示例
- PostgreSQL存储过程简单示例
- oracle存储过程简单示例
- mysql存储过程简单示例
- MySQL 触发器、存储过程、事务简单示例
- 存储过程触发器job简单示例
- SqlServer_存储过程变量操作简单示例;
- 简单mysql数据库存储过程示例
- MySQL 触发器 存储过程 自定义函数 视图 简单示例
- oracle中函数和存储过程简单示例-动态sql
- oracle存储过程实现增删改简单示例
- java 调用mysql的存储过程(简单示例)
- sql中存储过程和游标简单示例
- oracle 存储过程 循环游标的简单实用示例
- 存储过程简单示例1 默认为in OUT
- 内部类实现机制
- 多线程计数器锁存器---CountDownLatch
- Oracle中TO_DATE格式
- 从地址栏输入到页面显示 -深入探究web运行机制
- HDOJ 1010:Tempter of the Bone 迷宫问题 解题报告
- 简单存储过程示例优化。。。多列取最小值
- linux 数据流重导向
- ASP.NET学习笔记[4] - 无法分析从服务器在通过调用 Response.Write()
- 【Cortex-M0】4 ARM微微控制器的指令集
- 基于Socket的通信机制-有连接通信方式:多线程通信
- Android图形系统分析与移植--六、framebuffer研究
- VS2010与SVN
- Android之短信发送器
- 好的软件人员一生必看的六十本书