Solved

Partial SQL Data copied from one table to another

Posted on 2014-04-03
8
366 Views
Last Modified: 2014-05-19
I have a table with a ton of fields and I need to pull out a select few and insert the data into another existing table.

Specifically:

Location
-------
field1
field2
field3
Client
ContractAmt
ContractDate
field7
field8

Contracts
--------
ContractType (this is going to be 21 for all records
Client (set to Client from Table1)
ContractStartDate (needs to be set to ContractDate -1 year)
ExpireDate (set to ContractDate from Table1)
ContractAmt (set to ContractAmt from Table1)


Tried this:
INSERT INTO Contracts (ContractType, Client, ContractStartDate, ExpireDate, ContractAmt) VALUES (SELECT 21, Client, DATEADD('yy', -1, ContractDate), ContractDate, ContractAmt FROM Location)

but I get
Msg 1023, Level 15, State 1, Line 2
Invalid parameter 1 specified for dateadd.
0
Comment
Question by:Lee W, MVP
  • 4
  • 3
8 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 39977342
try

INSERT INTO Contracts
(ContractType, Client, ContractStartDate, ExpireDate, ContractAmt)
SELECT 21, Client, DATEADD('yy', -1, ContractDate), ContractDate, ContractAmt FROM Location
0
 
LVL 95

Author Comment

by:Lee W, MVP
ID: 39977356
Nope,
Msg 1023, Level 15, State 1, Line 4
Invalid parameter 1 specified for dateadd.
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 39977381
INSERT INTO Contracts
(ContractType, Client, ContractStartDate, ExpireDate, ContractAmt)
SELECT 21, Client, DATEADD(year, -1, ContractDate), ContractDate, ContractAmt FROM Location
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 95

Author Comment

by:Lee W, MVP
ID: 39977472
I've requested that this question be closed as follows:

Accepted answer: 0 points for pratima_mcs's comment #a39977381

for the following reason:

Thanks, that did the trick!
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 39977473
it helps you right? then why 0 points ?
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 39982226
thats fine. I just want to understand whether he needs more help in that.
0
 
LVL 95

Author Comment

by:Lee W, MVP
ID: 40075857
Sorry - that was a screwup on my part - your assistance was greatly appreciated (It was a late project for me so probably didn't have my head on straight...)
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question