1 Use [Mct]2 GO3 /** * * * object:storedprocedure [dbo]. [P_counticcardtradinfo] Script date:05/20/2015 09:04:45 * * * * **/4 SETAnsi_nulls on5 GO6 SETQuoted_identifier on7 GO8 9 ALTER PROCEDURE [dbo].[P_counticcardtradinfo]Ten ( One @bdate datetime, A @edate datetime, - @CusName varchar( -), - @CardCode varchar( -), the @BusinessType varchar( -), - @UserCode varchar( -) - ) - as + Declare @strSql varchar(Max) - Set @strSql='Select Recordtime,cardcode,cuscode,relname,boothcode,deposit,usercode,businesstype,businessvalue from # Temptabletradinfocount where 1=1'; + A BEGIN at --create temporary tables for saving data - Create Table#TempTableTradInfoCount - ( - -Recordtimedatetime not NULL, -Cardcodevarchar(Ten) not NULL, inCuscodevarchar( -) not NULL, -Relnamevarchar( -) not NULL, toBoothcodevarchar( -) not NULL, +Depositdecimal(Ten,2) not NULL, -Usercodevarchar( -) not NULL, theBusinesstypevarchar( -) not NULL, *Businessvaluevarchar( -) not NULL $ )Panax Notoginseng - if(@bdate is not NULL) and(@bdate!="') the Set @strSql= @strSql + 'and CONVERT (varchar (), recordtime,120) >=" "+CONVERT(varchar(Ten),@bdate, -)+" '" ; + A if(@edate is not NULL) and(@edate!="') the Set @strSql= @strSql + 'and CONVERT (varchar (), recordtime,120) <=" "+CONVERT(varchar(Ten),@edate, -)+" '" ; + - if(@CusName is not NULL) and(@CusName!="') $ Set @strSql= @strSql + 'and relname =" " + @CusName +" '"; $ - if(@CardCode is not NULL) and(@CardCode!="') - Set @strSql= @strSql + 'and Cardcode =" " + @CardCode+" '" ; the - if(@BusinessType is not NULL) and(@BusinessType!="')Wuyi Set @strSql= @strSql + 'and Businesstype =" " + @BusinessType+" '" ; the - if(@UserCode is not NULL) and(@UserCode!="') Wu Set @strSql= @strSql + 'and Usercode =" " + @UserCode +" '"; - About --print @strsql; $ - --Main card - Insert into#TempTableTradInfoCount (Recordtime,cardcode,cuscode,relname,boothcode,deposit,usercode,businesstype, Businessvalue) - SelectEDITDATE,ICCARDNOCPU,KH_DM,KH_MC,"',0, Usecode,'Maincard','Main card' fromKhdawhereIccardnocpu!="' and(Usecode!='Y' orUsecode!='y') A + --Secondary Card the Insert into#TempTableTradInfoCount (Recordtime,cardcode,cuscode,relname,boothcode,deposit,usercode,businesstype, Businessvalue) - SelectEDITDATE,PARTCARDNO,KHDM,KHMC,"', Ysje,usercode,'Vicecard','Secondary Card' fromIccardcopyrecord $ the --Temporary card regularization the Insert into#TempTableTradInfoCount (Recordtime,cardcode,cuscode,relname,boothcode,deposit,usercode,businesstype, Businessvalue) the SelectPd. Recordtime,cus. Iccardnocpu,cus. Kh_dm,cus. KH_MC,"'Pd. Deposit,registration,'Temcard','Temporary card' fromPositivedeposit PDInner JoinKhda cus onPd. Customercord=cus. KH_DM the - --Reporting Loss in Insert into#TempTableTradInfoCount (Recordtime,cardcode,cuscode,relname,boothcode,deposit,usercode,businesstype, Businessvalue) the SelectLOSSRQ,CARDCODE,KHDM,KHMC,"', Gsf,usercode,'Losscard','Reporting Loss' fromIccardloss the About --return card the Insert into#TempTableTradInfoCount (Recordtime,cardcode,cuscode,relname,boothcode,deposit,usercode,businesstype, Businessvalue) the SelectEDITDATE,CARDCODE,KHDM,KHMC,"', Tkf,usercode,'Backcard','return card' fromIccardreturn the + exec(@strSql); - the END
stored procedures in SQL Server where conditions need to be judged for stitching