Solved

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

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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
triggered use of sp_send_dbmail failure 2 22
Linking a DMV to a database id/sql text in SQL server 2008 8 45
SQL Exceptions 3 35
mysql joining from the same table 6 29
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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 is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

929 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

10 Experts available now in Live!

Get 1:1 Help Now