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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL SERVER 2000, basic question 2

Status
Not open for further replies.

pssheba

Programmer
Oct 22, 2004
87
IL
Hi !
i want to operate arithmetic calculations on varchar data types. How do i transform it into numeric ?
Thanks.
 
all you need to do is cast it as an interger so....

Code:
declare @v varchar(20)
set @v = '10'

declare @i int

select @i = (select cast(@v as int))


select i = @i/2
 
Here is one way, but you may want to cast the columns as float if you are expecting decimals:
Code:
select 'calculated value' = case when isnumeric(columnA) and isnumeric(columnB) then cast(columnA as int)+cast(columnB as int) else 'Not numeric' end
from table1
 
Thanks a lot guys!
I also found why it didnt work for me. I imported data from a text file and first line was the titles...
Thats why i couldnt implement any cast to numeric. At least i can use your suggestions that broaden my ability to make conversions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top