Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Partial SQL Data copied from one table to another

Posted on 2014-04-03
8
Medium Priority
?
391 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 96

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 2000 total points
ID: 39977381
INSERT INTO Contracts
(ContractType, Client, ContractStartDate, ExpireDate, ContractAmt)
SELECT 21, Client, DATEADD(year, -1, ContractDate), ContractDate, ContractAmt FROM Location
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 96

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 96

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

604 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