Tuesday, March 20, 2012

conversion

Hi All,
I am pretty new to sql server. I have a column with data in the format
of #ddd,dddd
where d is a number between 0 and 9.
e.g. one entry of column #34,56
What is the easiest way to convert it to integer? #56,5-->565
Thanks a lot
Thanks.So the comma is not significant? If so, try:
select
cast (replace (replace (MyCol, '#', ''), ',', '') as int)
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
<jack.smith.sam@.gmail.com> wrote in message
news:1162070389.388509.50190@.m7g2000cwm.googlegroups.com...
Hi All,
I am pretty new to sql server. I have a column with data in the format
of #ddd,dddd
where d is a number between 0 and 9.
e.g. one entry of column #34,56
What is the easiest way to convert it to integer? #56,5-->565
Thanks a lot
Thanks.|||If you want to permanently convert the column datatype to integer, use
Tom's suggestion to clear the non-numeric characters out of the current
column, and then use
ALTER TABLE MyTable
ALTER COLUMN Mycolumn int
--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf
<jack.smith.sam@.gmail.com> wrote in message
news:1162070389.388509.50190@.m7g2000cwm.googlegroups.com...
> Hi All,
> I am pretty new to sql server. I have a column with data in the format
> of #ddd,dddd
> where d is a number between 0 and 9.
> e.g. one entry of column #34,56
> What is the easiest way to convert it to integer? #56,5-->565
> Thanks a lot
> Thanks.
>

No comments:

Post a Comment