Solved

Partial SQL Data copied from one table to another

Posted on 2014-04-03
8
365 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help creating a spatial object in SQL Server 4 22
optimize stored procedure 6 27
sql server service accounts 4 26
Syntax for query to update table 2 12
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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

773 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