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 2008 Forums
 SQL Server Administration (2008)
 Simple Insert

Author  Topic 

mikebird
Aged Yak Warrior

529 Posts

Posted - 2013-01-22 : 18:00:29
INSERT INTO [dbo.Tesco Delivery] (Date, Qty, Description, Price, Total)
SELECT '2010-10-19'
,[Quantity]
,[Product]
,[Price]
,[Total]

FROM [dbo].[Tesco del 19 Oct 2010]

the source table has the same fields, apart from the date, which I want to add manually. The select runs fine, returning exactly what I want to see. I cant tell if the error moans about the field names in the select or the insert clause. Line 2 shows the insert clause has the problem? Do the field names really have to match? I tried the select ... into... from... structure, but found this better for adding the date. Do I need to add / remove any paranthesis here?

The question is: How to I add the date manually? There is an auto IDENTITY (1,1) on the first column of the destination

why these errors?


Msg 207, Level 16, State 1, Line 2
Invalid column name 'Date'.
Msg 207, Level 16, State 1, Line 2
Invalid column name 'Qty'.
Msg 207, Level 16, State 1, Line 2
Invalid column name 'Description'.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2013-01-22 : 18:19:04
INSERT INTO [dbo].[Tesco Delivery] ([Date], [Qty], [Description], [Price], [Total])
SELECT '2010-10-19'
,[Quantity]
,[Product]
,[Price]
,[Total]

FROM [dbo].[Tesco del 19 Oct 2010]

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

mikebird
Aged Yak Warrior

529 Posts

Posted - 2013-01-22 : 18:37:03

Impeccable.

I was shocked by those changes. That's all it takes! I thought the only need for squares was to contain names with spaces

Thanks!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2013-01-23 : 12:56:57
You need it for reserved words too, but I think the real problem was with [dbo.Tesco Delivery].

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -