SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 Simple Insert
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mikebird
Aged Yak Warrior

United Kingdom
529 Posts

Posted - 01/22/2013 :  18:00:29  Show Profile  Reply with Quote
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'.

Edited by - mikebird on 01/22/2013 18:10:22

tkizer
Almighty SQL Goddess

USA
36636 Posts

Posted - 01/22/2013 :  18:19:04  Show Profile  Visit tkizer's Homepage  Reply with Quote
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

United Kingdom
529 Posts

Posted - 01/22/2013 :  18:37:03  Show Profile  Reply with Quote

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

USA
36636 Posts

Posted - 01/23/2013 :  12:56:57  Show Profile  Visit tkizer's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000