SQL 提高查询速度
输入参数声明(略)----------------------------------------declare@strvarchar(max)set@str='sele...
输入参数声明(略)
----------------------------------------
declare @str varchar(max)
set @str = 'select RTRIM(left(CONVERT(varchar(5), 日期, 0),2)) + ''月'' as 月份,CONVERT(varchar(100),日期,23) as 日期,单号,
case when substring(产品编号,1,1) = ''A'' then ''添加剂'' when substring(产品编号,1,1) =''B'' then ''包装袋'' when substring(产品编号,1,1) =''D'' then ''软包装'' when substring(产品编号,1,1) =''G'' then ''罐装''
when substring(产品编号,1,1) =''P'' then ''山露'' when substring(产品编号,1,1) =''L'' then ''标签''
when substring(产品编号,1,1) =''Q'' then ''其它'' when substring(产品编号,1,1) =''S'' then ''山菜''
when substring(产品编号,1,1) =''Z'' then ''纸箱'' END as 产品分类,发货人,收货人, sum(abs(数量))as 数量 ,单价, sum(金额) as 金额 from '+ @ckgs +' where substring(产品编号,1,1) like '''+ @cpfl +''' and 单据分类 like '''+@djfl+''' and 产品名称 like '''+@cpmc+''' and 发货人 like '''+@ffr +''' and 收货人 like ''' +@sfr+''' group by 日期,单号,产品编号, 发货人,收货人,单价'
exec (@str)
这种查询如何写有助于提高速度? 展开
----------------------------------------
declare @str varchar(max)
set @str = 'select RTRIM(left(CONVERT(varchar(5), 日期, 0),2)) + ''月'' as 月份,CONVERT(varchar(100),日期,23) as 日期,单号,
case when substring(产品编号,1,1) = ''A'' then ''添加剂'' when substring(产品编号,1,1) =''B'' then ''包装袋'' when substring(产品编号,1,1) =''D'' then ''软包装'' when substring(产品编号,1,1) =''G'' then ''罐装''
when substring(产品编号,1,1) =''P'' then ''山露'' when substring(产品编号,1,1) =''L'' then ''标签''
when substring(产品编号,1,1) =''Q'' then ''其它'' when substring(产品编号,1,1) =''S'' then ''山菜''
when substring(产品编号,1,1) =''Z'' then ''纸箱'' END as 产品分类,发货人,收货人, sum(abs(数量))as 数量 ,单价, sum(金额) as 金额 from '+ @ckgs +' where substring(产品编号,1,1) like '''+ @cpfl +''' and 单据分类 like '''+@djfl+''' and 产品名称 like '''+@cpmc+''' and 发货人 like '''+@ffr +''' and 收货人 like ''' +@sfr+''' group by 日期,单号,产品编号, 发货人,收货人,单价'
exec (@str)
这种查询如何写有助于提高速度? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询