[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Insert fields into a table from another table as distinct

Posted on 2014-08-21
3
Medium Priority
?
143 Views
Last Modified: 2014-09-06
why does this statement fail and what should it be? there are other fields in the table which all accept null so do i have to add them too?


 insert into SageMasterAddresses (account_ref)
  values
  select distinct(account_ref)
  from SageSalesnEW where SLXAccountREFID is null
0
Comment
Question by:Chris Michalczuk
3 Comments
 
LVL 15

Expert Comment

by:Vikas Garg
ID: 40278454
Hello

You should not use values while inserting from SQL statement
it is used only when passing static values

Try this

insert into SageMasterAddresses (account_ref)
  select distinct(account_ref)
  from SageSalesnEW where SLXAccountREFID is null

Open in new window

0
 
LVL 66

Accepted Solution

by:
Jim Horn earned 1500 total points
ID: 40278732
>why does this statement fail
For starters, a statement like 'why does this fail' could be answered easier if you provide us the error message that returns when it is executed.

>what should it be?
Along the same lines, you tell us what you're trying to do here.

>there are other fields in the table which all accept null so do i have to add them too?
Yes.  If there are ANY fields other than account_ref that do not accept NULLS, then the above statement will fail, and yes you'll need to pass them like this...
insert into SageMasterAddresses (account_ref, column1, column2, column3)
select distinct(account_ref), NULL, NULL, NULL
from SageSalesnEW 
where SLXAccountREFID is null

Open in new window

0
 
LVL 32

Expert Comment

by:awking00
ID: 40279258
Some relevant sample data for the SageSalesnEW table and what you would like to see in the SageMasterAddresses table would be most helpful.
0

Featured Post

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!

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
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
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

872 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