字段拼接 装换

USE [Ecom]
GO
/****** Object:  StoredProcedure [dbo].[R_Merchant_PreOrder_ChargesData]    Script Date: 03/15/2016 13:43:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[R_Merchant_PreOrder_ChargesData]
    @Type Nvarchar(400),  
    @MerchantID Nvarchar(400),
    @EffectiveDate Nvarchar(400),
    @NarmalSelling Nvarchar(400)
AS
BEGIN
    if(@Type = ‘Without‘)
    begin
        if(@NarmalSelling = ‘‘ or @MerchantID = ‘‘)
        begin
            select ‘Please Enter NarmalSelling‘
            select ‘Please Enter NarmalSelling‘
        end
        else
        begin
        select * into #a from(
        select d.ID,
               d.MerchantID,
               d.State,
               d.EffectiveDate,
               d.ChargesType,
               d.ChargesName,
               d.ChargesCode,
               d.InvoiceCol,
               d.ValueType,
               d.Value,
               @NarmalSelling as NarmalSelling,
               Tax= Case
                    WHEN c.ValueType = ‘Rate‘ THEN @NarmalSelling*abs(cast(c.Value as decimal(18,2)))
                    WHEN c.ValueType = ‘Number‘ THEN @NarmalSelling-abs(cast(c.Value as decimal(18,2)))
                    ELSE ‘0‘ END,
               Comments = (select REPLACE(case when ValueType = ‘Rate‘ then
                                   CAST(CAST(Value * 100 AS float) as nvarchar(20)) + ‘% ‘ else ‘$‘ +
                               CAST(CAST(Value as Float) as nvarchar(20)) + ‘ ‘ end, ‘-‘, ‘‘) + ChargesCode
                               from Config_Order_Charges b where d.ID = b.ID FOR xml path(‘‘))
        from Config_Order_Charges d
        left join
        (select *
        from Config_Order_Charges
        where ID in(
            select MAX(ID) as ID
            from Config_Order_Charges a
                inner join
                (select ChargesName,
                        MAX(EffectiveDate) EffectiveDate
                from Config_Order_Charges  
                group by ChargesName,MerchantID
                having MerchantID = @MerchantID) b
                on a.ChargesName=b.ChargesName and a.EffectiveDate=b.EffectiveDate
                where a.MerchantID = @MerchantID
                group by a.ChargesName)) c
        on c.ID = d.ID
        where d.MerchantID = @MerchantID) g
        select * from #a order by ChargesName,EffectiveDate desc,ID desc
        select * into #c from(select MerchantID,InvoiceCol,
                                     SUM(Tax) as TotalTaxValue
                                     from #a group by InvoiceCol,MerchantID having [email protected]) h
        select a.InvoiceCol,
               a.TotalTaxValue,
               stuff((SELECT ‘ and ‘ + c.Comments FROM #a AS c Where c.MerchantID = a.MerchantID and a.InvoiceCol=c.InvoiceCol and c.Tax != 0 FOR xml path(‘‘)), 1, 5, ‘‘) AS Comments    
               from #c a
        drop table #a
        drop table #c
        end
    end
    else if(@Type = ‘Indoor‘)
    begin
        if(@NarmalSelling = ‘‘ or @MerchantID = ‘‘)
        begin
            select ‘Please Enter NarmalSelling‘
            select ‘Please Enter NarmalSelling‘
        end
        else
        begin
        select * into #b from(
        select d.ID,
               d.MerchantID,
               d.State,
               d.EffectiveDate,
               d.ChargesType,
               d.ChargesName,
               d.ChargesCode,
               d.InvoiceCol,
               d.ValueType,
               d.Value,
               @NarmalSelling as NarmalSelling,
               Tax= Case
                    WHEN c.ValueType = ‘Rate‘ THEN @NarmalSelling*abs(cast(c.Value as decimal(18,2)))
                    WHEN c.ValueType = ‘Number‘ THEN @NarmalSelling-abs(cast(c.Value as decimal(18,2)))
                    ELSE ‘0‘ END,
                Comments = (select REPLACE(case when ValueType = ‘Rate‘ then
                            CAST(CAST(Value * 100 AS float) as nvarchar(20)) + ‘% ‘ else ‘$‘ +
                            CAST(CAST(Value as Float) as nvarchar(20)) + ‘ ‘ end, ‘-‘, ‘‘) + ChargesCode
                            from Config_Order_ChargesToPreView b where d.ID = b.ID FOR xml path(‘‘))
        from Config_Order_ChargesToPreView d
        left join
        (select *
        from Config_Order_ChargesToPreView
        where ID in(
            select MAX(ID) as ID
            from Config_Order_ChargesToPreView a
                inner join
                (select ChargesName,
                        MAX(EffectiveDate) EffectiveDate
                from Config_Order_ChargesToPreView  
                group by ChargesName,MerchantID
                having MerchantID = @MerchantID) b
                on a.ChargesName=b.ChargesName and a.EffectiveDate=b.EffectiveDate
                where a.MerchantID = @MerchantID
                group by a.ChargesName)) c
        on c.ID = d.ID
        where d.MerchantID = @MerchantID) h
        select * from #b order by ChargesName,EffectiveDate desc,ID desc
        select * into #d from (select MerchantID,InvoiceCol,
                                      SUM(Tax) as TotalTaxValue
                                      from #b
                                      group by InvoiceCol,MerchantID
                                      having [email protected]) k
        select a.InvoiceCol,
               a.TotalTaxValue,
               stuff((SELECT ‘ and ‘ + c.Comments FROM #b AS c Where c.MerchantID = a.MerchantID and a.InvoiceCol=c.InvoiceCol and c.Tax != 0 FOR xml path(‘‘)), 1, 5, ‘‘) AS Comments    
               from #d a                              
        drop table #b
        drop table #d
        end
    end
END

时间: 2024-08-09 10:36:23

字段拼接 装换的相关文章

原生函数和强制类型装换

var a = new String("abc"); console.log(typeof a); //是Object,而不是string 使用new String("abc"); 创建的是字符串 abc 的封装对象,而不是基本类型值"abc". 封装对象 由于基本类型值没有.length和.toString()这样的属性和方法,需要通过封装对象才能访问,此时JavaScript会自动为基本类型值包装一个封装对象,如: var a = "

DataSet装换为泛型集合

/// <summary> /// DataSet装换为泛型集合 /// </summary> /// <typeparam name="MoDeviceAbnormalStateRecord"></typeparam> /// <param name="p_DataSet">DataSet</param> /// <param name="p_TableIndex"&

DataSet装换为泛型集合 222

#region DataSet装换为泛型集合 /// <summary> /// 利用反射和泛型 /// </summary> /// <param name="dt"></param> /// <returns></returns> public static List<T> ConvertToList<T>(DataTable dt) { // 定义集合 List<T> ts

mysql 多个字段拼接

Mysql的查询结果行字段拼接,能够用以下两个函数实现: 1. concat函数 mysql> select concat('1','2','3') from test ; +---------------------+ | concat('1','2','3') | +---------------------+ | 123 | +---------------------+ 假设连接串中存在NULL,则返回结果为NULL: mysql> select concat('1','2',NULL

opencv之深拷贝及浅拷贝,IplImage装换为Mat

一.(1)  浅拷贝: Mat B; B = image  // 第一种方式 Mat C(image); // 第二种方式 这两种方式称为浅copy,是由于它们有不同的矩阵头,但是它们共享内存空间,即指向一个矩阵.当图像矩阵发生变化时,两者相关联,都会变化. (2)深拷贝 Mat B,C; B = image.clone();       // 第一种方式 image.copyTo(C); // 第二种方式 深拷贝是真正的copy了一个新的图像矩阵,此时image,B,C三者相互没有影响. 二.

oracle中的装换函数

日期装换成字符的函数:TO_CHAR(date[,fmt[,params]]) 默认格式:DD-MON-RR 参数说明: date:将要装换的日期 fmt:装换的格式 params:日期的语言(可以不写)例子: SQL> select to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') from dual; TO_CHAR(SYSDATE,'YY ------------------- 2016-04-21 07:55:54 字符型转换成日期的函数: TO_DATE

Conversion of feet/inches to meters-英尺、英里装换为米

Conversion of feet/inches to meters-英尺.英里装换为米,允许重复计算: //Conversion of feet/inches to meters-英尺.英里装换为米,允许重复计算 #include<iostream> #include<cmath> using namespace std; void get_input(double& feet,double& inch); double convert(double& 

mvc 解决StyleBundle中 图片绝对路径 装换成相对路径的问题

问题 解决办法 mvc 解决StyleBundle中 图片绝对路径 装换成相对路径的问题

整数装换为字符串intToArray与字符串转为整数 arrayToInt实现

7.  整数装换为字符串itoa的实现 1 char *intToArray(int number, char *str) 2 { 3 if(str == NULL) 4 { 5 return NULL; 6 } 7 char *ret = str; 8 char *left = str; 9 char temp = '\0'; 10 // 负数的处理 11 if(number < 0) 12 { 13 number = -number; 14 *ret++ = '-'; 15 left++;