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
Solved

additional varchar field using a select into statement

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Amazon RDS migrate to SQL Server 3 24
Stored Proc - Rewrite 42 56
TSQL XML Namespaces 7 21
MS SQL Delete Duplicate Rows Only 2 15
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.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

809 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