Solved

Mixing constants with INSERT INTO

Posted on 2011-09-21
2
225 Views
Last Modified: 2012-05-12
I have values from a temp table that need to be inserted into an existing table.  However, I will hard code some of the values going in.  How do I mix these hard coded values with the INSERT INTO...SELECT?  Or is a different technique needed?
0
Comment
Question by:brettr
2 Comments
 
LVL 14

Accepted Solution

by:
mds-cos earned 250 total points
Comment Utility
No problem!  You just can't wildcard the fields.

INSERT INTO intable (infield1, infield2, infield3, ...)
SELECT outfiled1, outfield2, 'hardcode',...
FROM outtable
0
 
LVL 92

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 250 total points
Comment Utility
No problem:

INSERT INTO SomeTable (col1, col2, col3, col4)
SELECT x, y, 'Fred', 123
FROM #my_temp

Open in new window


First two columns from the temp table, last two as constants.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
execute a MS SQL script as a schedule SQL job 72 97
SQl query 19 12
Row-Level Security 2 15
replication - alerts? 4 19
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 …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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

772 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

14 Experts available now in Live!

Get 1:1 Help Now