程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> 其他數據庫知識 >> 更多數據庫知識 >> 將count(*)值寫入另一個表中的方法

將count(*)值寫入另一個表中的方法

編輯:更多數據庫知識

一、寫入同一個數據庫的另一個表中:  
復制代碼 代碼如下:
use db1  
go  
create table t1(  
Item   varchar(100),  
Prov   varchar(100),  
Qty    int);  
insert into t1(item,prov,qty)  
   select '原名','xx省',  
(select count(*)   
from updata where id='A0101'); 


二、寫入另一個數據庫的表中:  
復制代碼 代碼如下:
use db2  
go  
create table t2(  
Item   varchar(100),  
Prov   varchar(100),  
Qty    int);  
INSERT   INTO  t2(item,prov,qty)   
select '原名',  
'xx省',  
(select count(*)  
FROM OPENDATASOURCE('SQLOLEDB',   
'Data Source=YY\IIDC;  
User ID=sa;  
Password=password').  
db1.dbo.updata where  
culindexid='A0101') 
 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved