Solved

Mixing constants with INSERT INTO

Posted on 2011-09-21
2
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
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.

717 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