Solved

additional varchar field using a select into statement

Posted on 2004-04-15
2
429 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
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.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

685 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