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
 General SQL Server Forums
 New to SQL Server Programming
 Convert

Author  Topic 

Clas
Starting Member

33 Posts

Posted - 2009-08-20 : 06:09:41
Hi.
How to convert nvarchar to int

It is an "make table" query.

Source Table:
Value nvarchar (50)

Value = 3
Value = 4
Value = 50
Value = 72


CASE Value
WHEN <=5 THEN 0 (int)
WHEN >5 THEN 1 (int)
END
AS ValueInt

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-08-20 : 06:11:52
CASE
WHEN Value > 5 THEN 1
ELSE CAST(0 AS INT)
END AS ValueInt


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-08-20 : 06:16:01
You can also make this directly in your "make table" query.

SELECT *, CAST( somecol AS int) AS [get the value as int],
CAST( somecol AS int) / 6 AS [get the value as flagged directly]
INTO #Temp
FROM ...


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

Clas
Starting Member

33 Posts

Posted - 2009-08-20 : 07:03:48
THANKS !
Go to Top of Page
   

- Advertisement -