首页 > 其他 > 详细

存储过程+联合查询返回字符串

时间:2017-12-26 00:27:19      阅读:263      评论:0      收藏:0      [点我收藏+]


if Exists(select name from sysobjects where NAME = ‘GetTable‘ and type=‘P‘)
drop procedure GetTable
go
CREATE PROCEDURE GetTable
@name nvarchar(50)=null,
@Time1 datetime=‘2017-03-07 00:00:00‘,
@Time2 datetime=null
AS
BEGIN
DECLARE @Str nvarchar(max)=‘‘
if @Time2 is null
BEGIN
set @Time2=GETDATE()
END
set @Str=‘SELECT w.ID,w.UserAccount,(SELECT COUNT(1) AS Expr1 FROM dbo.BI6WebSiteUser AS c WHERE (ParentAgencyID = w.ID) AND (UserType = 2)) AS Agentcount
isnull(SUM(p.Paymoney),0) as RechargeAmount,isnull(Sum(isnull(p.AgentDividedMoney,0)),0) as CommissionAmount
from dbo.WebSiteUser as w , dbo.Boing_PayHheOrderForm as p
where w.ID=p.AgentDividedID and p.IsDelete=1 and p.CreateTime>=‘+@Time1+‘ and p.CreateTime<=‘+@Time2
if @name is not null
BEGIN
set @Str+=‘ and UserAccount=‘+@name
END

set @Str+=‘ GROUP BY w.ID,w.UserAccount‘
Return @Str
END

--declare @SrtDate nvarchar(max)
execute GetTable NULL,‘2017-12-05 17:35:27.193‘
--print @SrtDate @SrtDate=

存储过程+联合查询返回字符串

原文:https://www.cnblogs.com/ZxtIsCnblogs/p/8004336.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!