Solved

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

Posted on 2015-02-06
3
191 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 65

Accepted Solution

by:
Jim Horn earned 460 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 10

Assisted Solution

by:HuaMinChen
HuaMinChen earned 40 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

840 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