Solved

Partial SQL Data copied from one table to another

Posted on 2014-04-03
8
361 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
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…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now