20191021

SQL同服务器跨库链表查询

select*from RZ191014.dbo.States l left join RB191014.dbo.States r on l.Code=r.StateCode collate Chinese_PRC_90_CI_AI

  20190903

单条数据插入

insert into RB190822.dbo.OceanCustomer values('66666','BlazeTest','sdf','sdf','15036363625','13111','3543434@qq.com','ShangHai','Shanghai','China','78965113',0)

 

批量数据插入

insert into RB190822.dbo.OceanCustomer

select Code,AgencyName,LastName,FirstName,Phone,Fax,Email,Address,City,State,ZipCode,IsAgent from OceamDB.dbo.OceanCustomer

 

   SQL 分布式查询

跨服务器数据库查询

SELECT * FROM OPENDATASOURCE('SQLOLEDB','Data Source=192.168.103.14;User ID=sa;Password=666666').RB190822.dbo.OceanCustomer

 

跨服务器导数据

insert into RB190822.dbo.OceanCustomer

select Code,AgencyName,LastName,FirstName,Phone,Fax,Email,Address,City,State,ZipCode,IsAgent from OPENDATASOURCE('SQLOLEDB','Data Source=192.168.103.14;User ID=sa;Password=666666').OceamDB.dbo.OceanCustomer

 

建表

create table OceanCustomer

(

Id int not null primary key identity(1,1),

AgencyCode varchar(50) ,

CompanyName varchar(50) ,

LastName varchar(50) ,

FirstName varchar(50) ,

Phone varchar(50) ,

Fax varchar(50) ,

Email varchar(50) ,

Address varchar(50) ,

City varchar(50) ,

State varchar(50) ,

ZipCode varchar(50) ,

IsAgent bit

)

 

加字段

alter table AgencyList add

Active  bit not null default 1,

AddedOn DateTime,

--如果从ocean来请显示ocean,如果是arc来的显示arc,如果是之后新增的,请显示online(如果有多个源头,请显示多个,比方:ocean, arc)

AddedBy varchar(100),

--记录被inactive日期

RemovedOn DateTime,

--是我们自己inactive的还是通过arc

RemovedBy varchar(100),

 

--WAS                       对应已有的 CompanyName

--PHYSICAL ADDRESS LINE1    对应已有的 CompanyAddress

--PHYSICAL ADDRESS LINE2    对应新增的 CompanyAddress2

CompanyAddress2 varchar(1000),

--PHYSICAL CITY             对应已有的 City

--PHYSICAL STATE            对应已有的 State

--Entity Type      含义未知           两个参数 Y/N   Y=>1,N=>0 如果觉得不好可以直接改字符串类型

EntityType bit,

--MAIL FLAG        邮箱是否可用??? 两个参数 Y/N   Y=>1,N=>0 如果觉得不好可以直接改字符串类型

MailFlag bit,

--OFFICE STATUS    

OfficeStatus varchar(5),

--MAILING NAME     邮箱

MailingName varchar(100),

--Mailing Address Line #1 

MailingAddressLine varchar(1000),

--MAILING ADDRESS LINE #2 

MailingAddressLine2 varchar(1000),

--MAILING CITY 

MailingCity varchar(100),

--MAILING STATE

MailingState varchar(100),

--MAILING ZIP CODE 

MailingZipCode varchar(100),

--第R列  ACCREDITATION TYPE

AccreditationType varchar(100),

--第S列  Additional Office Type Codes

AdditionalOfficeTypeCode varchar(100),

--联系人

ContactName varchar(100),

ContactTitle varchar(100),

--促销信息

PromotionalAgencyEmail varchar(100),

PromotionalAgencyEmailFirstName varchar(100),

PromotionalAgencyEmailLastName varchar(100),

PromotionalAgencyEmailTitle varchar(100)

 

修改数据类型

alter table AgencyList

alter column AgencyUserId nvarchar(100) null

 

自动发邮件需要配置sc

Windows sc命令

https://blog.csdn.net/Moruna/article/details/9190733

 

sc create MyServer binPath= "E:\NewSysterm\AA2017\Affordable2017\AAAutoSendEmail\bin\Debug\AAAutoSendEmail.exe" DisplayName= "我的定时服务" start= "Auto"

 

游标导数据

所有后台账号可以访问所有报表的团

declare @Id int

declare cur cursor fast_forward for

   select Id from RB190508.dbo.AdminUser where [State]=1;  --Common数据库的AdminUserId

open cur;

fetch next from cur into @Id

while @@fetch_status=0

begin

insert into AW190429.dbo.AdminUser_Packages (AdminUserId,PackageId) values(@Id,0) --导入到AW新建的表里,默认全选

begin

print(@Id)

end

    fetch next from cur into @Id;

end

close cur;

deallocate cur;

付钱成功但是因为入库报错的订单数据修正

declare @content varchar(100)

declare @transactionId varchar(11)

declare @count int

declare cur cursor fast_forward for

   select [Content] from [dbo].[AdminLog] 

where OPtype like 'CreditCard' AND Content like '%/1/1/%' AND OPtime > '2019-04-16';

open cur;

fetch next from cur into @content;

while @@fetch_status=0

begin

set @transactionId = (select RIGHT(@content, 11)); --截取成功付款的log中的transactionid

set @count = (select count(*) from TourOrder_CardHolder where TransactionId = @transactionId)

 

--输出不在cardholder里的transaction记录

if(@count = 0)

begin

print(@content)

end

    fetch next from cur into @content;

end

close cur;

deallocate cur;

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐