Sunday, February 19, 2012

FORMAT

Hi! I have a query that goes like:
SELECT price * profit AS unit_price FROM tbl_price WHERE id_item = 10
Then, I use this unit_price as a displayMember property of a VB.Net combo
box. The problem is that I have some thing like unit_price = 10.189800, I
would like to have only 2 decimals. How can I format the returned field
right in the query? I know there is a FORMAT function in access, but it
seems not to be in MSDE... Anyone!? I really need to format this, since
it's pretty lame to display a price qwith 6 decimals... ya know well
thank yall! I'll be around, if you have any question!
Jean Christophe Avard
Try this:
SELECT CAST(price * profit as decimal(10,2)) AS unit_price FROM tbl_price
WHERE id_item = 10
Nedi Freguglia
"Jean Christophe Avard" wrote:

> Hi! I have a query that goes like:
> SELECT price * profit AS unit_price FROM tbl_price WHERE id_item = 10
> Then, I use this unit_price as a displayMember property of a VB.Net combo
> box. The problem is that I have some thing like unit_price = 10.189800, I
> would like to have only 2 decimals. How can I format the returned field
> right in the query? I know there is a FORMAT function in access, but it
> seems not to be in MSDE... Anyone!? I really need to format this, since
> it's pretty lame to display a price qwith 6 decimals... ya know well
> thank yall! I'll be around, if you have any question!
> Jean Christophe Avard
>
>
|||Hi,
Use convert function with numeric data type.
SELECT convert(numeric(10,2),price * profit) AS unit_price FROM tbl_price
WHERE id_item = 10
Thanks
Hari
SQL Server MVP
"Jean Christophe Avard" <NO.SP@.M.XXXXX> wrote in message
news:uHlBeNWrFHA.2540@.TK2MSFTNGP09.phx.gbl...
> Hi! I have a query that goes like:
> SELECT price * profit AS unit_price FROM tbl_price WHERE id_item = 10
> Then, I use this unit_price as a displayMember property of a VB.Net combo
> box. The problem is that I have some thing like unit_price = 10.189800, I
> would like to have only 2 decimals. How can I format the returned field
> right in the query? I know there is a FORMAT function in access, but it
> seems not to be in MSDE... Anyone!? I really need to format this, since
> it's pretty lame to display a price qwith 6 decimals... ya know well
> thank yall! I'll be around, if you have any question!
> Jean Christophe Avard
>
|||On Tue, 30 Aug 2005 09:01:02 -0400, "Jean Christophe Avard" <NO.SP@.M.XXXXX>
wrote:

> Hi! I have a query that goes like:
> SELECT price * profit AS unit_price FROM tbl_price WHERE id_item = 10
> Then, I use this unit_price as a displayMember property of a VB.Net combo
> box. The problem is that I have some thing like unit_price = 10.189800, I
> would like to have only 2 decimals. How can I format the returned field
> right in the query? I know there is a FORMAT function in access, but it
> seems not to be in MSDE... Anyone!? I really need to format this, since
> it's pretty lame to display a price qwith 6 decimals... ya know well
> thank yall! I'll be around, if you have any question!
> Jean Christophe Avard
Download the SQL Server Books Online, you'll find a wealth of information
in it, most of which applies to MSDE as well.
http://www.microsoft.com/sql/techinf...000/books.mspx
Then look up the ROUND function in it.
If you want to return a numeric string from your query instead of a rounded
floating point value, combine ROUND with CONVERT.
|||THANK YOU ALL DUDES!!!
Thank you Luc for the online book!
"Jean Christophe Avard" <NO.SP@.M.XXXXX> wrote in message
news:uHlBeNWrFHA.2540@.TK2MSFTNGP09.phx.gbl...
> Hi! I have a query that goes like:
> SELECT price * profit AS unit_price FROM tbl_price WHERE id_item = 10
> Then, I use this unit_price as a displayMember property of a VB.Net combo
> box. The problem is that I have some thing like unit_price = 10.189800, I
> would like to have only 2 decimals. How can I format the returned field
> right in the query? I know there is a FORMAT function in access, but it
> seems not to be in MSDE... Anyone!? I really need to format this, since
> it's pretty lame to display a price qwith 6 decimals... ya know well
> thank yall! I'll be around, if you have any question!
> Jean Christophe Avard
>

No comments:

Post a Comment