Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Troubleshoot SQL Statement

Author  Topic 

andrthad
Starting Member

19 Posts

Posted - 2006-01-22 : 00:15:34
hi all,

I am not sure why this state is not working. Would you please explain why and tell me of a fix.

INSERT tblRevHistory (dteDateLogged, NoProdNumbers) VALUES(getdate(), SELECT Count(*) FROM weblogin.tbl_MASTER)

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-22 : 00:54:39
use of VALUES does not allow subqueries. Change to SELECT instead.

INSERT tblRevHistory (dteDateLogged, NoProdNumbers) select getdate(), (SELECT Count(*) FROM tbl_MASTER)


-----------------
'KH'

Go to Top of Page

andrthad
Starting Member

19 Posts

Posted - 2006-01-22 : 13:03:26
Absolutely brilliant. Thanks.
Go to Top of Page

nosepicker
Constraint Violating Yak Guru

366 Posts

Posted - 2006-01-22 : 14:46:44
Although, you don't need the second SELECT:

INSERT tblRevHistory (dteDateLogged, NoProdNumbers) select getdate(), Count(*) FROM tbl_MASTER

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-23 : 02:41:55
or

declare @count int
select @count=Count(*) FROM tbl_MASTER
INSERT tblRevHistory (dteDateLogged, NoProdNumbers) VALUES(getdate(), @Count)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -