|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Conversionyes
-- Show quotethanks, ------------------------------------ Jose de Jesus Jr. Mcp,Mcdba Data Architect Sykes Asia (Manila philippines) MCP #2324787 "Chandra" wrote: > Hi, > > Can I convert an nvarchar field to numeric type? > > Thanks > Chandra try
Cast (myNvarCharTableColumn as numeric) Show quote "Chandra" wrote: > Hi, > > Can I convert an nvarchar field to numeric type? > > Thanks > Chandra Hi,
declare @t nvarchar(10) set @t='10' select convert(numeric(5,2),@t) Ensure that you have no character data in te column Thanks Hari SQL Server MVP Show quote "RioDD" <Ri***@discussions.microsoft.com> wrote in message news:641160B8-BA5D-4FF4-92E3-76C39B2FA79B@microsoft.com... > try > Cast (myNvarCharTableColumn as numeric) > > "Chandra" wrote: > >> Hi, >> >> Can I convert an nvarchar field to numeric type? >> >> Thanks >> Chandra I tried Hari's solution but it is giving the following error.
Server: Msg 8114, Level 16, State 5, Line 1 Error converting data type nvarchar to numeric. what could be the reason? Thanks Chandra Show quote "Hari Prasad" wrote: > Hi, > > declare @t nvarchar(10) > set @t='10' > select convert(numeric(5,2),@t) > > Ensure that you have no character data in te column > > Thanks > Hari > SQL Server MVP > > "RioDD" <Ri***@discussions.microsoft.com> wrote in message > news:641160B8-BA5D-4FF4-92E3-76C39B2FA79B@microsoft.com... > > try > > Cast (myNvarCharTableColumn as numeric) > > > > "Chandra" wrote: > > > >> Hi, > >> > >> Can I convert an nvarchar field to numeric type? > >> > >> Thanks > >> Chandra > > > Obviously your nvarchar column contains values that cannot be converted to
the numeric data type. Read my other post in this thread. It's imperative that you test values before attempting to cast/convert them, since in some circumstances conversions even if successful can lead to unexpected results. And when it comes to numbers certain aspects of life can become devastated by such faults. ML >I tried Hari's solution but it is giving the following error. The reason is that you have non-numeric data in your NVARCHAR column. How > > Server: Msg 8114, Level 16, State 5, Line 1 > Error converting data type nvarchar to numeric. > > what could be the reason? is this supposed to work? SELECT CONVERT(NUMERIC(5,2), 'fooblat$%xpq@g') ? Of course, I do. But I haven't applied that specific hotfix to my
production SQL Servers yet. :-) Show quote "ML" <M*@discussions.microsoft.com> wrote in message news:D5B6DD32-14D3-4413-998F-8F2789EE7747@microsoft.com... > Don't you know that 'fooblat$%xpq@g' = 42? > > :) > > > ML Storing salaries as varchar might not be such a bad idea after all:
replace(salary, '.', 'e') ;) ML Also look at this recent thread for some details on numeric data types:
http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.sqlserver.programming&mid=caa4c151-1c7b-4b05-8f71-b7768b43fcf3
....in case you missed it. ML |
|||||||||||||||||||||||