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
 to_char equivalent convert function

Author  Topic 

aakcse
Aged Yak Warrior

570 Posts

Posted - 2010-06-14 : 12:28:22
I was trying to convert the below oracle code to sqlserver 2005

select TO_CHAR(OPTION_PRICE, '9999.999999') from table...

select convert(varchar,OPTION_PRICE) from table...

so far it looks good, giving correct results, but I am bit worried it may fail? could anyone provide some information on it plz.




-Neil

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-06-14 : 12:34:06
varchar without length (i.e. varchar(25) or so) is dangerous because there is a default length (I don't know maybe 10).

See also here for more info:
http://msdn.microsoft.com/de-de/library/ms187928.aspx


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-06-14 : 13:36:53
well I know the Char default is 1

What's with all the Oracle questions these days????



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2010-06-14 : 13:38:05
Use the STR() function to format numbers in SQL Server:

SELECT STR(OPTION_PRICE, 10, 6) FROM table
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-06-14 : 13:46:24
the VARCHAR default is 30 characters.



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

aakcse
Aged Yak Warrior

570 Posts

Posted - 2010-06-14 : 13:56:10
Thanks All,

well I know the Char default is 1

Brett, I have a code(few application proc) written in oracle, which I need to convert to sqlserver hmm facing lot of problem
I'll try using STR if any problem arise in testing the code later on, once again thanks all.

Thanks.

-Neil
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-06-14 : 14:03:47
why does it need to be converted?

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-15 : 02:30:44
quote:
Originally posted by Peso

the VARCHAR default is 30 characters.



N 56°04'39.26"
E 12°55'05.63"



It depends on how you use it

http://beyondrelational.com/blogs/madhivanan/archive/2007/12/04/column-length-and-data-length.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

aakcse
Aged Yak Warrior

570 Posts

Posted - 2010-06-15 : 02:31:31
Brett,

We need to convert it because Oracle is Client system and we doing analysis in SQL and we do not have Oracle at our end, as like wise there are over 100dbs to be migrated from different systems to SQL(migrated succesfully), however when it comes to Oracle it is bit difficult.


-Neil
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-15 : 02:34:19
quote:
Originally posted by robvolk

Use the STR() function to format numbers in SQL Server:

SELECT STR(OPTION_PRICE, 10, 6) FROM table


Only if there is no front end application to do it

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

aakcse
Aged Yak Warrior

570 Posts

Posted - 2010-06-15 : 02:46:20
hmm what could be the problem with varchar with out length

-Neil
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-15 : 02:53:24
quote:
Originally posted by aakcse

hmm what could be the problem with varchar with out length

-Neil


Did you read my first reply?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

aakcse
Aged Yak Warrior

570 Posts

Posted - 2010-06-15 : 05:47:19
Yes Maddy I read all of your reply

-Neil
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-06-15 : 05:49:54
quote:
Originally posted by aakcse

hmm what could be the problem with varchar with out length

-Neil


So what you are asking?
Do you have a problem or do you want to know if problems could occur?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

aakcse
Aged Yak Warrior

570 Posts

Posted - 2010-06-15 : 07:31:11
Thanks All

was trying to know if problems could occur

Thanks again


-Neil
Go to Top of Page
   

- Advertisement -