Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to convert string to numeric?

Author  Topic 

yulichka
Starting Member

2 Posts

Posted - 2008-09-29 : 14:06:48
How to convert string to How to convert string to integer??

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-29 : 14:18:54
use CAST or CONVERT

http://doc.ddart.net/mssql/sql70/ca-co_1.htm
Go to Top of Page

shan
Yak Posting Veteran

84 Posts

Posted - 2008-09-29 : 14:23:10
Use cast function

DECLARE @myval varchar(10)
SET @myval = '193'
SELECT CAST(@myval AS int)
-- Or, using CONVERT
SELECT CONVERT(int, @myval
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-29 : 14:25:52
quote:
Originally posted by shan

Use cast function

DECLARE @myval varchar(10)
SET @myval = '193'
SELECT CAST(@myval AS int)
-- Or, using CONVERT
SELECT CONVERT(int, @myval)


mind the braces
Go to Top of Page

shan
Yak Posting Veteran

84 Posts

Posted - 2008-09-29 : 15:16:01
thanks for correcting :-)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-30 : 04:07:22
quote:
Originally posted by shan

Use cast function

DECLARE @myval varchar(10)
SET @myval = '193'
SELECT CAST(@myval AS int)
-- Or, using CONVERT
SELECT CONVERT(int, @myval


Provided it has no special characters or alphabets

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -