Solved

Mixing constants with INSERT INTO

Posted on 2011-09-21
2
229 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

726 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