?
Solved

insert varchar data into a float column.

Posted on 2006-05-18
2
Medium Priority
?
1,284 Views
Last Modified: 2012-08-14
hi,

how can i insert varchar (that holds numeric values e.g 200) data  from one table into a float column in another table?

thanks.
0
Comment
Question by:JakeyCakes
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 16707847
note AGAIN that you should NOT use float data type if not really necessary.
decimal/numeric  or int/bigint are in most cases better suited and avoid some problems.

anyhow:

insert into table2 (float_field) select cast( varchar_field as float ) from table1
0
 
LVL 75

Assisted Solution

by:Aneesh Retnakaran
Aneesh Retnakaran earned 1000 total points
ID: 16710997
Do we really need casting here, the sql server will use implicit conversion

for example

declare @float float
declare @varchar varchar(32)

set @varchar = '12.222'
set @float = @varchar

select @float


so your query

insert into table2 (float_field) select  varchar_field  from table1
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Suggested Courses

571 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