0

我有这样的声明:

 insert into Admin.VersionHistory --do not know what to put here
 select COUNT(*) as cnt
 from membership.members as mm 
 left join aspnet_membership as asp
 on mm.aspnetuserid=asp.userid 
 left join trade.tradesmen as tr 
 on tr.memberid=mm.memberid  
 where asp.isapproved = 0 and tr.ImportDPN IS NOT NULL and tr.importDPN <> ''

它总共给了我 179956。我想把这个总数写到另一个名为的表中Admin.VersionHistory,该表具有 id(autoinc)、version(varchar) 和 date(sysdate) 列,

请问我该怎么做?谢谢

4

3 回答 3

1

您的查询返回一列一行的结果集。它可以插入到某个具有一个整数列的表中。您的目标表不适合这样做,因为它有三列。

于 2012-09-19T09:25:25.883 回答
0
INSERT INTO Admin.VersionHistory (ColCount, version, Sysdate)
VALUES(  

(SELECT COUNT(*) AS cnt  FROM membership.members AS mm     
lLEFT JOIN aspnet_membership AS asp ON mm.aspnetuserid = asp.userid   
LEFT JOIN trade.tradesmen AS tr ON tr.memberid=mm.memberid   
WHERE   
asp.isapproved = 0 AND   
tr.ImportDPN IS NOT NULL AND   
tr.importDPN <> ''),   
VERSIONVALUE, GETDATE())  

虽然我在 Oracle 中尝试过类似的事情,但我想它在 SQL 中应该不会有太大的不同。

试一试。

于 2012-09-19T13:23:50.643 回答
0

你应该能够做到这一点:

INSERT INTO Admin.VersionHistory(ColumnName) 
SELECT COUNT(*)
-- the resut of your query here
于 2012-09-19T09:25:35.803 回答