Solved

Mixing constants with INSERT INTO

Posted on 2011-09-21
2
226 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
ID: 36577415
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
ID: 36577418
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

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.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

863 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

23 Experts available now in Live!

Get 1:1 Help Now