sqlserver数据销,sql销售

请问 sqlserver 统计销售量的语句怎么写?

转载的,能用!

创新互联公司从2013年创立,是专业互联网技术服务公司,拥有项目做网站、网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元和平做网站,已为上家服务,为和平各地企业和个人服务,联系电话:028-86922220

------------

CREATE PROCEDURE Pagination

@tblName varchar(255), -- 表名

@strGetFields varchar(1000) = '*', -- 需要返回的列

@fldName varchar(255)='', -- 排序的字段名

@PageSize int = 10, -- 页尺寸

@PageIndex int = 1, -- 页码

@doCount bit = 0, -- 返回记录总数, 非 0 值则返回

@OrderType bit = 0, -- 设置排序类型, 非 0 值则降序

@strWhere varchar(1500) = '' -- 查询条件 (注意: 不要加 where)

AS

declare @d datetime

set @d=getdate()

declare @strSQL varchar(5000) -- 主语句

declare @strTmp varchar(110) -- 临时变量

declare @strOrder varchar(400) -- 排序类型

if @doCount != 0

begin

if @strWhere !=''

set @strSQL = 'select count(*) as Total from ['+ @tblName +'] where '+ @strWhere

else

set @strSQL = 'select count(*) as Total from ['+ @tblName +']'

end

--以上代码的意思是如果@doCount传递过来的不是0,就执行总数统计。以下的所有代码都

--是@doCount为0的情况

else

begin

if @OrderType != 0

begin

set @strTmp = '(select min'

set @strOrder = ' order by ['+ @fldName +'] desc'

--如果@OrderType不是0,就执行降序,这句很重要!

end

else

begin

set @strTmp = '(select max'

set @strOrder = ' order by ['+ @fldName +'] asc'

end

if @PageIndex = 1

begin

if @strWhere != ''

set @strSQL = 'select top ' + str(@PageSize) +' '+@strGetFields+ ' from ['+ @tblName +'] where ' + @strWhere + ' ' + @strOrder

else

set @strSQL = 'select top ' + str(@PageSize) +' '+@strGetFields+ ' from ['+ @tblName +'] '+ @strOrder

--如果是第一页就执行以上代码,这样会加快执行速度

end

else

begin

--以下代码赋予了@strSQL以真正执行的SQL代码

set @strSQL = 'select top ' + str(@PageSize) +' '+@strGetFields+ ' from [' + @tblName +'] where [' + @fldName + ']' + @strTmp + '(['+ @fldName + '])

from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['+ @fldName + '] from ['+ @tblName +']' + @strOrder + ') as tblTmp)'+ @strOrder

if @strWhere != ''

set @strSQL = 'select top ' + str(@PageSize) +' '+@strGetFields+ ' from ['+ @tblName +'] where [' + @fldName + ']' + @strTmp + '(['+ @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['+ @fldName + ']

from ['+ @tblName +'] where ' + @strWhere + ' ' + @strOrder + ') as tblTmp) and ' + @strWhere + ' ' + @strOrder

end

end

exec ( @strSQL)

select datediff(ms,@d,getdate()) as 查询时间毫秒

go

Pagination 'CopyrightInformation','*','id',120,45667,0,0,''

服务器上的SQLserver怎么把数据库备份或者复制到本地

1、打开SqlServer数据库,选中要备份的数据库,【右键】选择【任务】,点击【备份】。

2、输入【数据集】名称,选择备份路径,点击【确定】就完成了数据库的备份。

3、【右键】选择【任务】,点击【还原】,选择【数据库】。

4、选择之前备份的数据库,点击【确定】。

5、至此SqlServer备份还原的操作就已完成。

教您如何简单删除SQLServer数据库的所有数据

也许很多读者朋友都经历过这样的事情:要在开发数据库基础上清理一个空库,但由于对数据库结构缺乏整体了解,在删除一个表的记录时,删除不了,因为可能有外键约束,一个常见的数据库结构是一个主表,一个子表,这种情况下一般都得先删除子表记录,再删除主表记录。 1.按照先后顺序逐个删除,这个方法在表非常多的情况下显得很不现实,即便是表数量不多,但约束比较多时,你还是要花费大量的时间和精力去研究其间的约束关系,然后找出先删哪个表,再删哪个表,最后又删哪个表。 首先得编写代码循环检查所有的表,这里我推荐一个存储过程sp_MSForEachTable,因为在微软的官方文档中没有对这个存储过程有描述,很多开发人员也许都还未曾听说,所以你在互联网上搜索得到的解决办法大多很复杂,也许有的人会认为,既然没有官方文档,这个存储过程可能会不稳定,打心理上会排斥它,但事实并非如此。下面来先看一个完整的脚本: 这个脚本创建了一个命名为sp_DeleteAllData的存储过程,前面两行语句分别禁用约束和触发器,第三条语句才是真正地删除所有数据,接下里的语句分别还原约束和触发器,最后一条语句是显示每个表中的记录,当然这条语句也可以不要,我只是想确认一下是否清空了所有表而已。

请问 sqlserver 各个商品各月销售额统计 sql语句怎么写????

可以完成,思路如下:

通过pid 商品编码分组,得到销售日期的每个月列,后用sum(case Fact_m WHEN 月份 then 数量end)来操作即可.

--年度售额:

select pid 商品编码

,isnull(convert(dec(18,2),sum(case Fact_m WHEN '01' then cCost end)),0) 'countCost_1'

,isnull(convert(dec(18,2),sum(case Fact_m WHEN '02' then cCost end)),0) 'countCost_2'

,isnull(convert(dec(18,2),sum(case Fact_m WHEN '03' then cCost end)),0) 'countCost_3'

,isnull(convert(dec(18,2),sum(case Fact_m WHEN '04' then cCost end)),0) 'countCost_4'

,isnull(convert(dec(18,2),sum(case Fact_m WHEN '05' then cCost end)),0) 'countCost_5'

,isnull(convert(dec(18,2),sum(case Fact_m WHEN '06' then cCost end)),0) 'countCost_6'

,isnull(convert(dec(18,2),sum(case Fact_m WHEN '07' then cCost end)),0) 'countCost_7'

,isnull(convert(dec(18,2),sum(case Fact_m WHEN '08' then cCost end)),0) 'countCost_8'

,isnull(convert(dec(18,2),sum(case Fact_m WHEN '09' then cCost end)),0) 'countCost_9'

,isnull(convert(dec(18,2),sum(case Fact_m WHEN '10' then cCost end)),0) 'countCost_10'

,isnull(convert(dec(18,2),sum(case Fact_m WHEN '11' then cCost end)),0) 'countCost_11'

,isnull(convert(dec(18,2),sum(case Fact_m WHEN '12' then cCost end)),0) 'countCost_12'

,isnull(convert(dec(18,2),sum(cCost))) 'countTotal' 

from Tab group by pid 

--Fact_m 指的就是销售日期[月],最后还有一列为年度总计

希望能帮到你!


文章名称:sqlserver数据销,sql销售
文章分享:http://pwwzsj.com/article/hcdihi.html