Showing posts with label types. Show all posts
Showing posts with label types. Show all posts

Monday, March 19, 2012

change data types

Hi,
The company I work is updating our software for
localization/internationalization. Unfortunately, when we built our backend
design, we did not foresee needing to go international. So almost all of
our text data types are not built for internationalization. Basically, the
only fields we really need to change are text and varchar, to ntext and
nvarchar. Are there any issues with running a SQL script as part of a
service pack, in order to change these data types in the tables?
If there are or aren't any problems, are there any articles someone can
point me to. Most articles I have found on localization deal specifically
with creating a new application.
So in summary, I need to know if there are any issues with changing a text
to an ntext and varchar to an nvarchar. Additionally, there may be some
char fields that need to be changed to nchar.
Any help/direction/articles would be very much appreciated. Thank you.
Paul
Well, one issue that pops to mind immediately is that if you have a
VARCHAR(8000) and it has 4001 characters or more, you're going to lose data.
NVARCHAR can only go to 4000, since every character takes two bytes.
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Paul" <paul@.gotheta.com> wrote in message
news:ebUJn1sMEHA.2628@.TK2MSFTNGP12.phx.gbl...
> Hi,
> The company I work is updating our software for
> localization/internationalization. Unfortunately, when we built our
backend
> design, we did not foresee needing to go international. So almost all of
> our text data types are not built for internationalization. Basically,
the
> only fields we really need to change are text and varchar, to ntext and
> nvarchar. Are there any issues with running a SQL script as part of a
> service pack, in order to change these data types in the tables?
> If there are or aren't any problems, are there any articles someone can
> point me to. Most articles I have found on localization deal specifically
> with creating a new application.
> So in summary, I need to know if there are any issues with changing a text
> to an ntext and varchar to an nvarchar. Additionally, there may be some
> char fields that need to be changed to nchar.
> Any help/direction/articles would be very much appreciated. Thank you.
> Paul
>

Sunday, February 12, 2012

cast('0.5' as numeric) + cast('0.5' as numeric) = 2 ???

Hi folks,
I want to talk about data types. I was of the impression that numeric
was a fixed data type. Why does sql 2005 exhibit the above behaviour
when casting to this datatype from a string?
Cheers,
Alex
The NUMERIC data type has precision and scale. Since you did not specify
scale in your CAST, the default scale of 0 is used. In that case the number
gets rounded to the decimal point and each CAST results in 1 for total of 2.
To CAST correctly you can specify scale 1:
SELECT CAST('0.5' AS NUMERIC(5, 1)) + CAST('0.5' AS NUMERIC(5, 1))
This will correctly return 1.
HTH,
Plamen Ratchev
http://www.SQLStudio.com

cast('0.5' as numeric) + cast('0.5' as numeric) = 2 ???

Hi folks,
I want to talk about data types. I was of the impression that numeric
was a fixed data type. Why does sql 2005 exhibit the above behaviour
when casting to this datatype from a string?
Cheers,
AlexThe NUMERIC data type has precision and scale. Since you did not specify
scale in your CAST, the default scale of 0 is used. In that case the number
gets rounded to the decimal point and each CAST results in 1 for total of 2.
To CAST correctly you can specify scale 1:
SELECT CAST('0.5' AS NUMERIC(5, 1)) + CAST('0.5' AS NUMERIC(5, 1))
This will correctly return 1.
HTH,
Plamen Ratchev
http://www.SQLStudio.com