try:
insert into yhye(CODE,iperiod,ccode_Name,dbill_date,md,mc,drye)
select Y.code,b.iperiod,a.ccode_Name,b.dbill_date,SUM(b.md),SUM(b.mc),SUM(b.md-b.mc)
FROM
ufdata_888_2004..code a,ufdata_888_2004..GL_accvouch b ,yhcode Y
where
a.ccode *=b.ccode and b.iperiod >=1 and b.iperiod <=12 and a.ccode like '10020%' and Y.ccode_name=a.ccode_Name
insert into yhye(CODE,iperiod,ccode_Name,dbill_date,md,mc,drye)
select Y.code,b.iperiod,a.ccode_Name,b.dbill_date,SUM(b.md),SUM(b.mc),SUM(b.md-b.mc)
FROM
ufdata_888_2004..code a,ufdata_888_2004..GL_accvouch b ,yhcode Y
where
a.ccode *=b.ccode and b.iperiod >=1 and b.iperiod <=12 and a.ccode like '10020%' and Y.ccode_name=a.ccode_Name
解决方案 »
- ?菜鸟求助,大数据表单如何整理查询思路
- 预定义SQL语句
- 再请vivianfdlpw()
- 有谁知道同步数据库会有什么后果?
- 来高手。依旧sql语句。。
- 求一求和SQL语句
- 网站链接服务器数据库遇到了由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败
- и璶开数誹库让远祘ㄏノ蔍数誹库该ń设﹚㎡????
- SQL遠程操作有什麼弊端?如果網絡穩定是否復制同步就沒意義了
- 一个奇怪的安装问题????
- 比较急,所以没问到非技术区去
- 请问这个常见的select怎么写?
--创建测试表
CREATE TABLE yhcode
(
i_id INT IDENTITY(1,1) NOT NULL,
code NVARCHAR(15) not NULL,
ccode_name NVARCHAR(100)
) go--drop trigger t_insert
--创建生成流水号的触发器
create trigger t_insert on yhcode
INSTEAD OF insert
as
declare @id varchar(18),@id1 int
select * into #tb from inserted
select @id=max(code) from yhcode
if @id is null
set @id1=0
else
Set @id1=cast(@id as int)update #tb set @id1=@id1+1
,code=right('0000'+cast(@id1 as varchar),4)
insert into yhcode(code,ccode_name) select code,ccode_name from #tb
go
--插入数据,进行测试
insert into yhcode(code,ccode_name)
select '','aa'
union all select '' ,'bb'
union all select '','cc'不过要注意code字段,写入时要这样
insert into yhcode(code,ccode_name)
select '','aa' 才不会出错或是改code字段允许为空
-----------------------------------
否则出code字段不允许为空错误