Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting Datatypes

Status
Not open for further replies.
Jul 16, 2004
153
Hello all,
I have a very large fixed length field text file that I have to import on a regular basis. When I import the data into my database this is fine, but what I need to do is change the data type.

Here is what I want to do:
1. Import the data to a temp_table
2. Transform data (ie char -> varchar)
3. Move data to real_table
4. Truncate temp_table

What is the best stratagy for doing this. I know about alter table but is there another way of doing this? I have to transform 205 columns everytime.

thanks
Mel

Thanks
 
Try Cast or conver as you desire.
Here is an example of cast.
select Cast (field1 as char (5)) from table1

Dr.Sql
Good Luck.
 
Cool,
Now when I do this for each field, do I do the following:

select Cast (field1 as char (5),
field2 as varchar (10),
field3 as int (1)
) from table1


Thanks

mel
 
Code:
select 
    Cast(field1 as char (5)) as 'field1',
    Cast(field2 as varchar (10)) as 'field2',
    Cast(field3 as int (1)) as 'field3'
from 
    table1

Rhys
Gene Roddenberry was a legendary pioneer of thought-provoking, futuristic science fiction. George Lucas created Jar Jar Binks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top