Home > Archive > MS SQL Server > October 2006 > conversion









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author conversion
jack.smith.sam@gmail.com

2006-10-31, 12:15 am

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.

Tom Moreau

2006-10-31, 12:15 am

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.


Arnie Rowland

2006-10-31, 12:15 am

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.
>



Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com