use xianning_xinghaian create table TDatabase ( FName VARCHAR(100) ) create table TTable ( FName VARCHAR(100) ) CREATE TABLE TColumn ( FTableName VARCHAR(100), FColumnName VARCHAR(100), FDataType VARCHAR(100), FLength INT ) CREATE TABLE TComment ( FText VARCHAR(8000) ) SELECT * FROM TTable SELECT * FROM TColumn WHERE FTableName = 'Jypubo.RightPower' SELECT * FROM TDatabase INSERT RS.master.dbo.TDatabase(FName) SELECT name FROM sysdatabases INSERT RS.master.dbo.TTable(FName) SELECT 'JyManageo.' + name FROM JyManageo.dbo.sysobjects WHERE type = 'U' INSERT rs.master.dbo.TColumn(FTableName,FColumnName,FDataType,FLength) SELECT A.name,B.name,type_name(b.xtype),length FROM syscolumns AS B,sysobjects AS A WHERE B.id = A.id AND A.type = 'U' ORDER BY A.name INSERT rs.master.dbo.TColumn(FTableName,FColumnName,FDataType,FLength) SELECT 'Jypubo.' + A.name,B.name,type_name(b.xtype),length FROM Jypubo.dbo.syscolumns AS B,Jypubo.dbo.sysobjects AS A WHERE B.id = A.id AND A.type = 'U' ORDER BY A.name SELECT * FROM TComment INSERT rs.master.dbo.TComment SELECT text FROM syscomments WHERE id = object_id('Get_Users') SELECT * FROM TColumn WITH(NOLOCK) DECLARE @sql VARCHAR(8000) SELECT @sql = 'CREATE TABLE csumStaff(' SELECT @sql = @sql + FColumnName + ' ' + FDataType + CASE WHEN FDataType LIKE '%char%' THEN '('+CAST(FLength AS VARCHAR)+'), ' ELSE ', ' END FROM TColumn WHERE FTableName = 'csumStaff' SELECT @sql = LEFT(@sql,LEN(@sql)-1) SELECT @sql = @sql + ')' PRINT @sql EXEC (@sql) --生成插入语句 DECLARE @Sql VARCHAR(1000) SELECT @Sql = '' SELECT @Sql = @Sql + FColumnName + ',' FROM TColumn WHERE FTableName = 'csumStaff' SELECT @sql = LEFT(@sql,LEN(@sql)-1) SELECT @sql = 'INSERT rs.master.dbo.csumStaff(' + @sql + ')SELECT ' + @sql + ' FROM csumStaff WITH(NOLOCK) WHERE ecode = ''whbb''' PRINT @Sql SELECT COUNT(1) FROM Comsume WITH(NOLOCK) SELECT * FROM Comsume WITH(NOLOCK) where shopid != 3 SELECT * FROM CardType SELECT * FROM ItemSet SELECT * FROM ShopSet SELECT * FROM Companys SELECT * FROM Config SELECT * FROM Business SELECT * FROM Territory SELECT * FROM PriceShop SELECT * FROM MainMenu SELECT * FROM Logloss SELECT * FROM PLmove SELECT * FROM CpgMge SELECT * FROM IsCoTreatment SELECT * FROM Staff WITH(NOLOCK) WHERE shopId = 3 SELECT * FROM UcardM WHERE 1=1 AND bcount > 0 AND ctFlag != 't' AND shopId = 3 SELECT * FROM CardType WHERE CtNo = 'zh010' SELECT * FROM csumItem WITH(NOLOCK) INSERT rs.master.dbo.Temp(ecode) SELECT ecode FROM users WITH(NOLOCK) GROUP BY ecode DELETE users SELECT * FROM users WITH(NOLOCK) WHERE shopId = 3 SELECT * FROM users WITH(NOLOCK) WHERE Telphone = '13971035808' SELECT sid FROM users WITH(NOLOCK) GROUP BY sid HAVING SUM(1) >1 SELECT COUNT(1) FROM users WITH(NOLOCK) CREATE TABLE Temp ( ecode VARCHAR(100) ) SELECT * FROM Temp WHERE ecode = 'whbb' SELECT * FROM UcardM WITH(NOLOCK) WHERE shopId = 3 SELECT count(1) FROM UcardM WITH(NOLOCK) DELETE UcardM WHERE sid NOT IN(SELECT sid FROM ) SELECT * FROM users WHERE cardNo = '30797' SELECT * FROM UcardM WHERE cardNo = '30797' CREATE TABLE Users ( sid VARCHAR(100), ecode VARCHAR(100), ShopId VARCHAR(100), Biz VARCHAR(100), CardNo VARCHAR(100), CardName VARCHAR(100), Sex VARCHAR(100), CredType VARCHAR(100), CredNo VARCHAR(100), HomeCall VARCHAR(100), Telphone VARCHAR(100), Birthday VARCHAR(100), CmpName VARCHAR(100), Job VARCHAR(100), CmpAdr VARCHAR(100), Logout VARCHAR(100), Logloss VARCHAR(100), Email VARCHAR(100), Pass VARCHAR(100), Credit VARCHAR(100), Qsng VARCHAR(100), Blood VARCHAR(100), StarSign VARCHAR(100), Love VARCHAR(100), sms VARCHAR(100), mcs VARCHAR(100), Ddate VARCHAR(100), UserCode VARCHAR(100), mni VARCHAR(100) ) CREATE TABLE UcardM ( sid VARCHAR(100), ecode VARCHAR(100), ShopId VARCHAR(100), Biz VARCHAR(100), CardNo VARCHAR(100), CtFlag VARCHAR(100), CtNo VARCHAR(100), Bcount VARCHAR(100), Balance VARCHAR(100), outshop VARCHAR(100), Ddate VARCHAR(100) ) /* CREATE PROCEDURE dbo.Get_Users ( @npos int, @ecode nvarchar(16), @ShopId int, @Biz nvarchar(8), @bt nvarchar(64), @et nvarchar(24) ) AS SET NOCOUNT ON; if @npos=0 --按时间段查询-- begin SELECT sid,ShopId,Biz,CardNo,CardName,Sex,CredType,CredNo,HomeCall,Telphone,Birthday,CmpName,Job,CmpAdr,Logout,Logloss,Email,Pass,UserCode, sms=case when sms=0 then 'false' else 'true' end,mcs FROM Users where ecode=@ecode and ShopId=@ShopId and Biz=@Biz and Ddate between @bt and @et and Logout=0 and Logloss=0 end else if @npos=1 --按卡号查询-- begin if @et='0' begin SELECT sid,ShopId,Biz,CardNo,CardName,Sex,CredType,CredNo,HomeCall,Telphone,Birthday,CmpName,Job,CmpAdr,Logout,Logloss,Email,Pass,UserCode, sms=case when sms=0 then 'false' else 'true' end,mcs FROM Users where ecode=@ecode and ShopId=@ShopId and Biz=@Biz and cardno=@bt and Logout=0 and Logloss=0 end else begin SELECT sid,ShopId,Biz,CardNo,CardName,Sex,CredType,CredNo,HomeCall,Telphone,Birthday,CmpName,Job,CmpAdr,Logout,Logloss,Email,Pass,UserCode, sms=case when sms=0 then 'false' else 'true' end,mcs FROM Users where ecode=@ecode and Biz=@Biz and cardno like '%' + @bt + '%' and Logout=0 and Logloss=0 end end else if @npos=2 --按姓名查询-- begin if @et='0' begin SELECT sid,ShopId,Biz,CardNo,CardName,Sex,CredType,CredNo,HomeCall,Telphone,Birthday,CmpName,Job,CmpAdr,Logout,Logloss,Email,Pass,UserCode, sms=case when sms=0 then 'false' else 'true' end,mcs FROM Users where ecode=@ecode and ShopId=@ShopId and Biz=@Biz and cardname like '%' + @bt + '%' and Logout=0 and Logloss=0 end else begin SELECT sid,ShopId,Biz,CardNo,CardName,Sex,CredType,CredNo,HomeCall,Telphone,Birthday,CmpName,Job,CmpAdr,Logout,Logloss,Email,Pass,UserCode, sms=case when sms=0 then 'false' else 'true' end,mcs FROM Users where ecode=@ecode and Biz=@Biz and cardname like '%' + @bt + '%' and Logout=0 and Logloss=0 end end else if @npos=3 --按电话查询-- begin if @et='0' begin SELECT sid,ShopId,Biz,CardNo,CardName,Sex,CredType,CredNo,HomeCall,Telphone,Birthday,CmpName,Job,CmpAdr,Logout,Logloss,Email,Pass,UserCode, sms=case when sms=0 then 'false' else 'true' end,mcs FROM Users where ecode=@ecode and ShopId=@ShopId and Biz=@Biz and Telphone=@bt and Logout=0 and Logloss=0 end else if @et='1' begin SELECT sid,ShopId,Biz,CardNo,CardName,Sex,CredType,CredNo,HomeCall,Telphone,Birthday,CmpName,Job,CmpAdr,Logout,Logloss,Email,Pass,UserCode, sms=case when sms=0 then 'false' else 'true' end,mcs FROM Users where ecode=@ecode and Biz=@Biz and Telphone=@bt and Logout=0 and Logloss=0 end else if @et='2' begin SELECT ecode,CardNo FROM Users where Telphone=@bt and Logout=0 and Logloss=0 end end --Logout=0 and Logloss=0 and -- else if @npos=4 --按生日月份查询-- begin SELECT sid,ShopId,Biz,CardNo,CardName,Sex,CredType,CredNo,HomeCall,Telphone,Birthday,CmpName,Job,CmpAdr,Logout,Logloss,Email,Pass,UserCode, sms=case when sms=0 then 'false' else 'true' end,mcs FROM Users where ecode=@ecode and ShopId=@ShopId and Biz=@Biz and (right('0'+left(stuff(Birthday,1,charindex('-',Birthday),''),charindex('-',stuff(Birthday,1,charindex('-',Birthday),''))-1),2)+'-'+ right('0'+reverse(left(reverse(Birthday),charindex('-',reverse(Birthday))-1)),2))=@bt and Logout=0 and Logloss=0 end else if @npos=6 --按卡型查询-- begin select top 20000 sid,ShopId,Biz,a.CardNo,CardName,Sex,CredType,CredNo,HomeCall,Telphone,Birthday,CmpName,Job,CmpAdr,Logout,Logloss,Email,Pass,UserCode, sms,mcs from ( SELECT sid,ShopId,Biz,CardNo,CardName,Sex,CredType,CredNo,HomeCall,Telphone,Birthday,CmpName,Job,CmpAdr,Logout,Logloss,Email,Pass,UserCode, sms=case when sms=0 then 'false' else 'true' end,mcs FROM Users where ecode=@ecode and ShopId=@ShopId and Biz=@Biz and Logout=0 and Logloss=0) a inner join (select cardno,ctno from UcardM where ecode=@ecode and ShopId=@Sho pId and ctFlag='n' and ctno=@bt) b on (a.cardno=b.cardno) end else if @npos=7 --按卡号段查询-- begin SELECT sid,ShopId,Biz,CardNo,CardName,Sex,CredType,CredNo,HomeCall,Telphone,Birthday,CmpName,Job,CmpAdr,Logout,Logloss,Email,Pass,UserCode, sms=case when sms=0 then 'false' else 'true' end,mcs FROM Users where ecode=@ecode and ShopId=@ShopId and Biz=@Biz and cardno between @bt and @et and Logout=0 and Logloss=0 end else if @npos=9 --按微信查询-- begin SELECT sid,ShopId,Biz,CardNo,CardName,Sex,CredType,CredNo,HomeCall,Telphone,Birthday,CmpName,Job,CmpAdr,Logout,Logloss,Email,Pass,UserCode, sms=case when sms=0 then 'false' else 'true' end,mcs FROM Users where ecode=@ecode and mcs=@bt end else if @npos=21 --按转卡号查询到新卡号-- begin SELECT CardNo FROM Computers where ecode=@ecode and ShopId=@ShopId and TimeEnd=@bt end else if @npos=8 --查询微信OPENID是否与卡号绑定过--ecode=@ecode and telphone=@et and mcs=@bt begin if not exists (SELECT telphone FROM Users where mcs=@bt) begin select a=1 -- from PLmove where sid=-1 end else begin SELECT mcs FROM Users where telphone=(SELECT top 1 telphone FROM Users where mcs=@bt) and len(mcs)<28 end end else if @npos=71 --根据顾客手机获取最近消费的店、服务的员工-- begin select b.shopid,b.mcs,b.stafname,a.stf,b.ecode from (SELECT top 1 ecode,shopid,stf=dbo.ColumnUnionStr(2,@ecode,ShopId,TitemNo,DitemNo,1) FROM Computers where ecode=@ecode and telphone=@et and preferential=0 order by ddate desc) a right join (select ecode,shopid,stafname,mcs=nowaddress,memo from Jypubo.dbo.Staff where ecode=@ecode and shopid=@ShopId) b on (a.ecode=b.ecode) order by b.memo asc --where a.stf is not null end else if @npos=79 --根据手机ID号获取ecode,shopid,telphone-- group by ecode,shopid,telphone,cardno,cardname,biz begin select a.ecode,a.telphone,a.cardname,d.en,appid=case when d.appid is null or d.appid='' or d.appid='0' then 'wx411c79dedfed3f2d' else d.appid end, msecret=case when d.msecret is null or d.msecret='' or d.appid='0' then '306120f957fd136526a6f8407431216f' else d.msecret end, tmpid=case when d.tmpid is null or d.tmpid='' or d.appid='0' then 'lEkvh7whX_eFswLXBUy3r5Vwx7Kb-DHH7hOXsminkso' else d.tmpid end, tmpid2=case when d.tmpid2 is null or d.tmpid2='' or d.appid='0' then 'ZjvQKrHoPQ79zBxMdIuot4Xmw_5CUtAtWcpstriqyYg' else d.tmpid2 end, tmpid3=case when d.tmpid3 is null or d.tmpid3='' or d.appid='0' then 'Lc-1fw5W8RRbH59Gd4X2i8FFmfVxSHMeC7e4xc4ptSc' else d.tmpid3 end, a.shopid,a.cardno,biz,d.ei,c.shopname,b.cri,d.dsc from (SELECT ecode,shopid=max(shopid),cardno=max(cardno),cardname=max(cardname),telphone,biz FROM Users where mcs=@bt group by ecode,telphone,biz) a left join (select ecode,shopid,cri=CriteriaCode from Jypubo.dbo.ShopCriteria) b on (a.ecode=b.ecode and a.shopid=b.shopid) left join (select ecode,shopid,shopname,acn=accountno from Jypubo.dbo.ShopSet) c on (a.ecode=c.ecode and a.shopid=c.shopid) left join (select ec=companycode,en=companyname,appid,msecret,tmpid,tmpid2,tmpid3,ei=case when right(legalname,1)='1' then companycode else 'jy' end,dsc=officeaddress from Jypubo.dbo.Companys) d on (a.ecode=d.ec) where en is not null end else if @npos=80 --手机端口读卡-- begin select a.cardno,a.cardname,a.mcs,b.ctno,b.balance,a.sex,m=right('0'+convert(nvarchar(2),a.m),2),d=right('0'+convert(nvarchar(2),a.d),2),b.ctFlag from (SELECT cardno,cardname,mcs,sex,m=month(birthday),d=day(birthday) FROM Users where ecode=@ecode and telphone=@et and Logout=0 and Logloss=0) a join (SELECT cardno,ctFlag,ctno,balance FROM UcardM where ecode=@ecode and ctFlag='n') b on (a.cardno=b.cardno) end else if @npos=81 --查询微信手机号在平台里是否存在--ecode=@ecode and begin SELECT mcs FROM Users where telphone=@et end else if @npos=82 --统计客户端会员绑定表--2017-03-17 begin select '店名'=convert(nvarchar(4),b.shopid)+'-'+b.shopname,'当前人数'=a.c1 from (SELECT shopid,c1=count(CardNo) FROM Users where ecode=@ecode and len(mcs)=28 group by shopid) a join (select shopid ,shopname from Jypubo.dbo.shopset where ecode=@ecode) b on (a.shopid=b.shopid) order by b.shopid end else if @npos=83 --查询余额 20180910 if exists (select cfg2 from Jypubo.dbo.Config where ecode=@ecode and shopid=1 and configtype='密码管理' and cfg1='提醒原价' and cfg2='1') begin select ec=c.CompanyName,b.CardNo,b.bs,b.bc,a.CardName,a.Telphone,b.cf from (SELECT ecode,shopid,CardNo,CardName,Telphone,mcs FROM Users where ecode=@ecode and mcs=@bt) a join (select ecode,shopid,CardNo,bs=balance,bc=bcount,cf=ctFlag from UcardM where ecode=@ecode and balance>0) b on (a.ecode=b.ecode and a.shopid=b.shopid and a.cardno=b.cardno) join JyPubo.dbo.Companys c on (a.ecode=c.Companycode) order by b.cf end else begin select ec=c.CompanyName,b.CardNo,b.bs,b.bc,a.CardName,a.Telphone,b.cf from (SELECT ecode,shopid,CardNo,CardName,Telphone,mcs FROM Users where ecode=@ecode and mcs=@bt) a join (select ecode,shopid,CardNo,bs=balance,bc=bcount,cf=ctFlag from UcardM where ecode=@ecode and ctFlag='n' and balance>0) b on (a.ecode=b.ecode and a.shopid=b.shopid and a.cardno=b.cardno) join JyPubo.dbo.Companys c on (a.ecode=c.Companycode) order by b.cf end else if @npos=84 --查询小程序手机号在平台里是否存在--ecode=@ecode and begin SELECT telphone FROM Users where ecode=@ecode and mni=@bt end else if @npos=5 --培训续费1个月时间提示 begin SELECT sid,ShopId,Biz,CardNo,username=CardName,Sex,CredType,CredNo,HomeCall,Telphone,Birthday,CmpName,Job,CmpAdr,Logout,Logloss,Email,Pass,ddate,UserCode, sms=case when sms=0 then 'false' else 'true' end,mcs FROM Users where ecode=@ecode and ShopId=@ShopId and Biz=@Biz and ((datediff(month,convert(varchar(10),Ddate,120),convert(varchar(10),getdate(),120))+1) % 12=0) end else if @npos=12 --统计全连锁店会员数量、各店会员数量-- begin if @ShopId=0 begin SELECT count(sid) c1 FROM Users where ecode=@ecode and Logout=0 and Logloss=0 -- select count(CardNo) c1 from Users where ecode=@ecode and Logout=0 and Logloss=0 and -- (select count(CardNo) from Users e where e.telphone=Users.telphone and e.cardname=Users.cardname) <2 end else begin SELECT count(sid) c1 FROM Users where ecode=@ecode and ShopId=@ShopId and Logout=0 and Logloss=0 -- select count(CardNo) c1 from Users where ecode=@ecode and ShopId=@ShopId and Logout=0 and Logloss=0 and -- (select count(CardNo) from Users e where ecode=@ecode and ShopId=@ShopId and e.telphone=Users.telphone and e.cardname=Users.cardname) <2 end end */ -------------------------------------- -- Import ALTER TABLE CardType ADD FId BIGINT UPDATE CardType SET FId = dbo.FNNewId() INSERT INTO TMemberCardType(FId,FNo,FName,FValueType,FMaterial,FPrice,FCardFeeAmt,FAcctId,FDeposit,FAcctId2,FDeposit2,FAcctId3,FDeposit3,FTimes,FAlertBalance,FMinRchgAmt,FSalePointMode,FSalePointValue,FRchgPointMode,FRchgPointValue,FPaySmsFee,FTimeCard,FValidityPeriod,FValidityPeriodUnit,FExpiredDate,FDefaultMemo,FCreateTime,FAllowSale,FAllowRchg,FDeptId,FEnabled,FOrder) SELECT FId,CtNo,CtName,1,2,0,0,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 FROM CardType UPDATE TMemberCardType SET FAllowRchg = 1 WHERE FId IN(SELECT FId FROM CardType) UPDATE TMemberCardType SET FAllowSale = 1 WHERE FId IN(SELECT FId FROM CardType) UPDATE TMemberCardType SET FEnabled = 1 WHERE FId IN(SELECT FId FROM CardType) UPDATE TMemberCardType SET FValidityPeriod = 100 WHERE FId IN(SELECT FId FROM CardType) UPDATE TMemberCardType SET FValidityPerioduNIT = 1 WHERE FId IN(SELECT FId FROM CardType) UPDATE TMemberCardType SET FExpiredDate = null WHERE FId IN(SELECT FId FROM CardType) UPDATE TMemberCardType SET FDeposit = 0,FDefaultMemo = '' WHERE FId IN(SELECT FId FROM CardType) INSERT INTO TMemberCardTypeSub(FId,FCompId,FCardTypeId,FAllowSale,FAllowRchg,FEnabled) SELECT dbo.FNNewId(),C.FId,I.FId,FAllowSale,FAllowRchg,FEnabled FROM TMemberCardType AS I,TCompany AS C WHERE I. FId IN(SELECT FId FROM CardType) AND C.FId = dbo.FNCompId('006') AND NOT EXISTS(SELECT TOP 1 1 FROM TMemberCardTypeSub AS B WHERE B.FCompId = C.FId AND B.FCardTypeId = I.FId) ALTER TABLE Users ADD FMemId BIGINT ALTER TABLE Users ADD FMemNo VARCHAR(50) ALTER TABLE Users ADD FName VARCHAR(50) ALTER TABLE Users ADD FGender INT ALTER TABLE Users ADD FMobile VARCHAR(50) ALTER TABLE Users ADD FCreateDate DATETIME ALTER TABLE Users ADD FCompId BIGINT ALTER TABLE Users ADD FArrear DECIMAL(18,6) ALTER TABLE Users ADD FPoint DECIMAL(18,6) ALTER TABLE Users ADD FBirthday DATETIME ALTER TABLE Users ADD FBirthdayType CHAR ALTER TABLE Users ADD FCustom1 VARCHAR(100) ALTER TABLE Users ADD FMemo VARCHAR(2000) ALTER TABLE Users ADD FPointText VARCHAR(100) ALTER TABLE UCardM ADD FMemId BIGINT ALTER TABLE UCardM ADD FCardNo VARCHAR(50) ALTER TABLE UCardM ADD FCardTypeId BIGINT ALTER TABLE UCardM ADD FCourseId BIGINT ALTER TABLE UCardM ADD FBalance DECIMAL(18,6) ALTER TABLE UCardM ADD FBalance2 DECIMAL(18,6) ALTER TABLE UCardM ADD FRemainTimes INT ALTER TABLE UCardM ADD FPurTimes INT ALTER TABLE UCardM ADD FPurAmount DECIMAL(18,6) ALTER TABLE UCardM ADD FItemId BIGINT ALTER TABLE UCardM ADD FCreateDate DATETIME ALTER TABLE UCardM ADD FExpiredDate DATETIME ALTER TABLE UCardM ADD FCompId BIGINT ALTER TABLE UCardM ADD FCardId BIGINT ALTER TABLE UCardM ADD FCategory VARCHAR(10) SELECT * FROM Users WHERE CardNo NOT IN(SELECT CardNo FROM UCardM) UPDATE Users SET FMemId = dbo.FNNewId() WHERE FMemId IS NULL UPDATE Users SET FCompId = dbo.FNCompId('006') UPDATE Users SET FName = CardName UPDATE Users SET FMemNo = CardNo UPDATE Users SET FMobile = Telphone UPDATE Users SET FGender = 1 WHERE Sex = '男' UPDATE Users SET FGender = 0 WHERE Sex != '男' UPDATE Users SET FMemo = ISNULL(Email,'') UPDATE Users SET FBirthdayType = 'G' SELECT * FROM UCardM UPDATE UCardM SET FCategory = 'Money' WHERE ctflag != 't' UPDATE UCardM SET FCardId = sid UPDATE UCardM SET FCompId = dbo.FNCompId('006') UPDATE A SET A.FMemId = B.FMEMId FROM UCardM AS A,Users AS B WHERE A.CardnO = B.CardnO update UCardM SET FExpiredDate = DATEADD(YEAR,100,FCreateDate) UPDATE A SET A.FCardTypeId = B.FId FROM UCardM AS A,CardType AS B WHERE A.ctNo = B.ctNo UPDATE UCardM SET FBalance = Balance UPDATE UCardM SET FCardNO = CardNo UPDATE UCardM SET FCreateDate = ddate UPDATE A SET A.FCardNo = B.FMemNO FROM Users AS B,UCardM AS A WHERE A.CardNo = B.CardNo DELETE TMember WHERE FMemId IN(SELECT sid FROM Users) SELECT * FROM TMember WHERE FMemNO like 'F%' SELECT * FROM TMember WHERE FMemNo IN(SELECT FMemNO FROM Users) SELECT * FROM Users WHERE FMemId = 3340511 SELECT * FROM Users SELECT * FROM TMember WHERE FCompId = 4639952966303055627 UPDATE Users SET FMemNo = 'CF' + FMemNo WHERE FMemNo IN(SELECT FCardNo FROM TMemberCard) UPDATE Users SET FMemNo = 'CF' + FMemNo WHERE FMemNo IN(SELECT FMemNo FROM TMember) SELECT FMemNO INTO #Member FROM Users GROUP BY FMemNO HAVING SUM(1) > 1 DROP TABLE #Member SELECT * FROM #Member ALTER TABLE Users ADD FSeq INT IDENTITY ALTER TABLE Users ADD FIndex INT UPDATE A SET A.FIndex = 1+(SELECT COUNT(1) FROM Users AS B WHERE A.FMemNo = B.FMemNo AND (A.FCreateDate > B.FCreateDate OR (A.FCreateDate = B.FCreateDate AND (A.FSeq > B.FSeq) ))) FROM Users AS A UPDATE Users SET FMemNo = FMemNo + '.' + CAST(FIndex AS VARCHAR) WHERE FMemNo IN( SELECT FMemNO FROM #Member) SELECT FCardNo into #Card FROM UCardM WHERE FCategory ='Money' AND FCardNo NOT IN(SELECT FMemNo FROM #Member) GROUP BY FCardNo HAVING(SUM(1)) > 1 ALTER TABLE UCardM ADD FSeq INT IDENTITY ALTER TABLE UCardM ADD FIndex INT UPDATE A SET A.FIndex = 1+(SELECT COUNT(1) FROM UCardM AS B WHERE A.FCardNo = B.FCardNo AND (A.FCreateDate > B.FCreateDate OR (A.FCreateDate = B.FCreateDate AND (A.FSeq > B.FSeq) ))) FROM UCardM AS A WHERE FCategory ='Money' UPDATE UCardM SET FCardNo = FCardNo + '.' + CAST(FIndex AS VARCHAR) WHERE FCardNo IN( SELECT FCardNo FROM #Card) AND FCardNo NOT IN(SELECT FMemNO FROM #Member) INSERT INTO TMember( FMemId, FMemNo, FName, FBriefCode, FTypeId, FCompId, FCreateDate, FGender, FBirthdayType, FBirthday,FTelephone,FMobilePhone,FQQ,FWeChat,FIdCard,FEmail,FAddress,FProId,FCPW,FQPW, FChargeEmpId,FPoint,FRecvConsSMS,FRecvBulkSMS,FMemo,FCustom1,FCustom2,FCustom3,FCustom4,FCustom5) SELECT FMemId AS FMemId, FMemNo AS FMemNo, FName AS FName, dbo.FNGetFirstPinYin(FName), 0 AS FTypeId, FCompId AS FCompId, ISNULL(FCreateDate ,'1900-01-01') AS FCreateDate, FGender AS FGender, FBirthdayType AS FBirthdayType, FBirthday AS FBirthday, '' AS FTelephone, ISNULL(FMobile,'') AS FMobilePhone, '' AS FQQ, '' AS FWeChat, '' AS FIdCard, '' AS FEmail, '' AS FAddress, 0 AS FProId, '' AS FCPW, '' AS FQPW, 0 AS FChargeEmpId, ISNULL( FPoint,0) AS FPoint, 1 AS FRecvConsSMS, 1 AS FRecvBulkSMS, ISNULL(FMemo,'') AS FMemo, '' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5 from Users WHERE FMemNO not in(SELECT FMemNO FROM #Member) INSERT INTO TMemberCard( FCardId, FCardNo, FCardFaceNo, FTypeId, FValueType, FCompId, FMemId, FState, FCreateDate, FExpiredDate, FTotalTimes, FUsedTimes, FSaleCompId, FSaleBillId, FMemo) SELECT FCardId AS FId, FCardNo AS FNo, FCardNo AS FFaceNo, FCardTypeId AS FTypeId, (SELECT FValueType FROM TMemberCardType WHERE FId = FCardTypeId) AS FValueType, FCompId AS FCompId, FMemId AS FMemId, 1 AS FState, FCreateDate AS FCreateDate, FExpiredDate AS FExpiredDate, ISNULL(FRemainTimes,0) AS FTotalTimes, 0 AS FUsedTimes, FCompId AS FSaleCompId, 0 AS FSaleBillId, ISNULL('','') AS FMemo FROM UCardM WHERE FCategory = 'Money' AND FCardNo NOT IN(SELECT FMemNO FROM Users_) INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo) SELECT FMemId,dbo.FNNewId(),FCardId AS FCardId,3,FBalance,FBalance,0,FCreateDate,NULL AS FExpiredDate,'' FROM UCardM AS A WHERE FMemId IN(SELECT FMemId FROM TMember) AND FCategory = 'Money' INSERT TMemberCardAcctHist(FId,FMemId,FCardId,FAcctId,FTime,FCardTypeId,FCompId,FBillType,FBizType,FTransId,FTransNo,FInAmount,FOutAmount,FBalance,FArrear,FRecordTime,FMemo) select dbo.FNNewId(),A.FMemId,A.FCardId,3,getdate(),A.FCardTypeId,A.FCompId,'DR','Import',0,'',A.FBalance,0,A.FBalance,0,getdate(),'从盛传中导入' FROM UCardM AS A WHERE FMemId IN(SELECT FMemId FROM TMember) AND FCategory = 'Money' SELECT * FROM rs.master.dbo.Comsume WHERE shopId = 3 AND CardNo = 'WH00105118' SELECT * FROM rs.master.dbo.csumItem WHERE shopId = 3 AND DItemNo IN (SELECT DItemNo FROM rs.master.dbo.Comsume WHERE shopId = 3 AND CardNo = 'WH00105118') SELECT * INTO Comsume FROM rs.master.dbo.Comsume SELECT * INTO Comsume FROM rs.master.dbo.CSumItem ALTER TABLE Comsume ADD FCompID BIGINT UPDATE Comsume SET FCompId = dbo.FNCompId('006') SELECT A.FCompId,A.DDate,A.DItemNo AS FBillNo,I.ImSecName, * FROM Comsume AS A,CSumItem AS B LEFT JOIN ItemSet AS I ON I.ItemId = B.ItemId WHERE CardNo = 'WH00105118' AND A.TItemNO = B.TItemNo AND A.DItemNo = B.DItemNo SELECT * FROM TTable SELECT count(1) FROM Users WITH(NOLOCK) WHERE CardNo NOT IN( SELECT 卡号 FROM TImpTransHist WITH (NOLOCK)) delete timptranshist SELECT * FROM ItemSet DELETE Comsume WHERE CardNo NOT IN(SELECT CardnO FROM Users) SELECT * FROM staff exec sp_addlinkedserver rs,'','SQLOLEDB','qd11.isaidao.com,1466' exec sp_addlinkedsrvlogin rs,'false',null,'test','asdf8888' --疗程 ALTER TABLE IsCoTreatment ADD FCourseId BIGINT,FItemId BIGINT UPDATE IsCoTreatment SET FCourseId = dbo.FNNewId(),FItemId = dbo.FNNewId() INSERT TItem(FId,FNo,FNoOfPad,FName,FAbbr,FTypeId,FBriefCode,FDescription,FPriceMode,FIsService,FStatTimes,FCustom1,FCustom2,FCustom3,FEnabled,FPrice,FVipPrice,FTime,FDctId,FPointMode,FPointValue,FDeptId,FAllowBooking) SELECT FItemId,'CF'+CtNo,CtName,CtName,CtName,0,dbo.FNGetFirstPinYin(CtName),'',1,1,1,'','','',1,0,0,0,0,0,0,0,1 FROM IsCoTreatment WHERE ctNo IN(SELECT ctNo FROM UCardM) INSERT INTO TCourse(FId,FNo,FName,FBriefCode,FItemId,FPackId,FSequence,FTypeId,FTimes,FFreeTimes,FDurable,FValidityPeriodUnit,FValidityPeriod,FCreateDate,FExpiredDate,FDescription,FEnabled,FPrice,FAmount,FCalcMode) SELECT FCourseId AS FId, 'CF' + A.CtNo + 'L1', A.CtName AS FName, '' AS FBriefCode, A.FItemId AS FItemId, 0 AS FPackId, 1 AS FSequence, (SELECT TOP 1 FId FROM TBasicType WHERE FKey = 'CourseType') AS FTypeId, 1 AS FTimes, 0 AS FFreeTimes, 0 AS FDurable, 0 AS FValidityPeriodUnit, 0 AS FValidityPeriod, getdate() AS FCreateDate, NULL AS FExpiredDate, '' AS FDescription, 1 AS FEnabled, 0 AS FPrice, 0 AS FAmount, 1 AS FCalcMode FROM IsCoTreatment AS A WHERE ctNo IN(SELECT ctNo FROM UCardM) SELECT * FROM UCardM WHERE FCategory != 'Money' UPDATE A SET A.FCardTypeId = B.FCourseId, A.FItemId = B.FItemID FROM UCardM AS A,IsCoTreatment AS B WHERE A.ctNo = B.ctNo AND A.FCategory = 'Course' UPDATE UCardM SET FPurTimes = bcount --疗程 INSERT TMemberCourse(FId,FMemId,FCourseId,FMemPackId,FItemId,FCompId,FPurTimes,FUsedPurTimes,FPurAmount,FFreeTimes,FFreeAmount,FPurchaseDate,FExpiredDate,FBizType,FTransId,FArrear,FDurable,FMemo,FCalcMode,FAdjustPrice) SELECT FCardId,FMemId,FCardTypeId,0,FItemId,FCompId,FPurTimes,0,FBalance,0,0,FCreateDate,FExpiredDate,'DR.Import',0,0,0,'从老系统中导入',1,0 FROM UCardM AS A WHERE A.FCategory = 'Course' INSERT INTO TMemberCourseLog(FId,FMemId,FCardId,FPackId,FCourseId,FTime,FInPurTimes,FInFreeTimes,FOutPurTimes,FOutFreeTimes,FCompId,FBillType,FBizType,FBillId,FBillNo,FBillDetailId,FRecordTime) SELECT dbo.FNNewId(),FMemId,A.FCardId AS FCardId,0, ISNULL(FCardTypeId,0),getdate(),FPurTimes,0,0,0,FCompId,'DR','Import',0,'',0,getdate() FROM UCardM AS A WHERE A.FCategory = 'Course'