June 12, 2012 at 3:49 pm
Hi,
I have a couple of tables in my database. One of them has 7 columns and the other has 16 columns. The data types and columns match for the 7 columns of table1 and hence per my requirement I need to move the values of the 7 columns of table1 to table2. But for the other 9 columns in table2 I need to hardcode them with a static value per column for all the rows. Is this possible?
Thanks much for help in advance
“If your actions inspire others to dream more, learn more, do more and become more, you are a leader.” -- John Quincy Adams
June 12, 2012 at 4:36 pm
Sure. This is a bit of psuedocode using 3 columns but it'll give you the gist:
INSERT INTO NewTable
(ColA, ColB, ColC)
SELECT
ot.ColA,
'Static1',
'Static2'
FROM
OldTable AS ot
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA
June 13, 2012 at 1:02 am
You can also use a derived column component to add new columns with static values.
But in my opinion, Craig's solution is the most straightforward.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply