Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How so select a value into a table, if the source table does not contain the value

Posted on 2015-02-06
3
Medium Priority
?
210 Views
Last Modified: 2015-02-07
I am selecting data from a temp table "#TEMP_TABLE" into another table "ADMIN_USERS" which is not temporary.
The temp table does not have one of the column values I need to insert into the database table "ADMIN_USERS".
The column that is missing from the temp table is named "SERVER_NAME", and is a non null field. I would like to just insert the word/name
"Practice Server" into this field. How can I do that? Can it be done in the select statement?


INSERT INTO ADMIN_USERS (
ASSOCIATE_NUMBER
FIRST_NAME
MIDDLE_NAME
LAST_NAME
SERVER_NAME -- Somehow set this field to the text "Practice Server". I don't know how to do it though??.
AGE
)
SELECT
ASSOCIATE_NUMBER
FIRST_NAME
MIDDLE_NAME
LAST_NAME
AGE
FROM #TEMP_TABLE
0
Comment
Question by:brgdotnet
3 Comments
 
LVL 66

Accepted Solution

by:
Jim Horn earned 1840 total points
ID: 40595175
Yes, just add the string..
INSERT INTO ADMIN_USERS (ASSOCIATE_NUMBER, FIRST_NAME, MIDDLE_NAME, LAST_NAME, SERVER_NAME, AGE)
SELECT ASSOCIATE_NUMBER, FIRST_NAME, MIDDLE_NAME, LAST_NAME, 'Practice Server', AGE
FROM #TEMP_TABLE

Open in new window

0
 
LVL 11

Assisted Solution

by:HuaMinChen
HuaMinChen earned 160 total points
ID: 40595277
Try
INSERT INTO ADMIN_USERS (
ASSOCIATE_NUMBER,
FIRST_NAME,
MIDDLE_NAME,
LAST_NAME,
SERVER_NAME, -- Somehow set this field to the text "Practice Server". I don't know how to do it though??.
AGE
)
SELECT
ASSOCIATE_NUMBER,
FIRST_NAME,
MIDDLE_NAME,
LAST_NAME,
'Practice Server',
AGE
FROM #TEMP_TABLE

Open in new window

0
 
LVL 2

Author Closing Comment

by:brgdotnet
ID: 40595738
Jim was first by about an hour, so I am giving him most of the points. Thanl you.
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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

879 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