Solved

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
php image upload 3 27
Log Backup 2 13
BULK LOGGED - log full 9 13
SQL Update Query - What's wrong with this. 18 11
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

705 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

19 Experts available now in Live!

Get 1:1 Help Now