Solved

additional varchar field using a select into statement

Posted on 2004-04-15
2
425 Views
Last Modified: 2006-11-17
Could someone please show me the syntax for the following:

I create a new table from an existing table, but want to create an additional varchar field:

select * into table2 from (select f1,f2, ' ' as NewField from table1) s

The newfield now has data type of varchar(1).

If I now want to update this field with data from another table, I receive an error as the updating data is of a length greater than one?

I do not first want to create table2 and then add the field, eg
select * into table2 from (select f1,f2 from table1) s and then
ALTER table2 ADD NewField varchar(25)

OR
I do not want to go into Design Table and then change the  data type once table2 has been created.

OR
select * into table2 from (select f1,f2, '                  ' as NewField from table1) s


Is there sytax something like this?
select * into table2 from (select f1,f2, NewField  as varchar(25) from table1) s





0
Comment
Question by:DGWParker
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 50 total points
ID: 10833162
Hi DGWParker,

Use

Select * Into Table2 From (Select f1,f2,Space(25) As NewField From Table1) s

Tim Cottee
Brainbench MVP for Visual Basic
http://www.brainbench.com
0
 

Author Comment

by:DGWParker
ID: 10833228
Thanks Tim
That is perfect
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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

762 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

21 Experts available now in Live!

Get 1:1 Help Now