Reputation: 29
I need to execute this script monthly to load a record count into at table:
select count([BG_BUG_ID])
from [uc_maint_maintenance_db].[td].[BUG]
I created a table with one column to contain the numeric output:
CREATE TABLE [dbo].[BG_BUG_ID]
(
[BG_BUD_ID_COUNT] [numeric](18, 0) NULL
)
I receive an error on the select statement when I execute the script below:
INSERT INTO [AdminDB].[dbo].[BG_BUG_ID](count)
VALUES (SELECT COUNT([BG_BUG_ID])
FROM [uc_maint_maintenance_db].[td].[BUG])
What am I doing wrong? The select runs fine on its own. Any ideas are greatly appreciated!
I need to make this insert into a stored procedure.
Upvotes: 1
Views: 1818
Reputation: 3993
INSERT INTO [AdminDB].[dbo].[BG_BUG_ID]
SELECT COUNT([BG_BUG_ID])
FROM [uc_maint_maintenance_db].[td].[BUG]
Upvotes: 0
Reputation: 28403
count
instead of
BG_BUD_ID_COUNT
.values
.Try like below
INSERT INTO [AdminDB].[dbo].[BG_BUG_ID](BG_BUD_ID_COUNT)
SELECT COUNT([BG_BUG_ID])
FROM [uc_maint_maintenance_db].[td].[BUG]
Upvotes: 0
Reputation: 8991
Remove values
:
Insert into [AdminDB].[dbo].[BG_BUG_ID](BG_BUD_ID_COUNT)
select count([BG_BUG_ID])
from [uc_maint_maintenance_db].[td].[BUG]
Upvotes: 1