Desktop version

Main > Forum > Learning > 1C Junior Developer Course > Custom Query - Round operation

Forum

Search UsersRules
Custom Query - Round operation
#1
Interested
Points:: 0
Joined:: Sep 30, 2020

Hello, I have writed a custom query in a dynamic list.I want to round up UnitPrice.As I hear,I must use CAST keyword.How can I do this?

The question is in 5.Module 4.Task.


SELECT
SalesProducts.Product AS Product,
SUM(SalesProducts.Quantity) AS Quantity,
AVG(SalesProducts.UnitPrice) AS UnitPrice,
SUM(SalesProducts.LineTotal) AS LineTotal
FR OM
Document.Sales.Products AS SalesProducts
WHERE
SalesProducts.LineTotal > ¶meter

GROUP BY
SalesProducts.Product

ORDER BY
LineTotal ASC

Profile
#2
Administrator
Points:: 0
Joined:: Oct 3, 2019

Hi Mesut,

yes, of course, you can use the CAST keyword for this. In your case it will look like this:

CAST(SalesProducts.UnitPrice AS NUMBER(15, 2))

or

CAST(SalesProducts.UnitPrice AS NUMBER(15, 0))

Profile
#3
Interested
Points:: 0
Joined:: Sep 30, 2020

I have tried but it gives an error message.

Profile
#4
Administrator
Points:: 0
Joined:: Oct 3, 2019

Please show me the full text of your query.

Profile
#5
Administrator
Points:: 0
Joined:: Oct 3, 2019

A, I see,

you should write like this:

Code
SELECT
SalesProducts.Product AS Product,
SUM(SalesProducts.Quantity) AS Quantity,

AVG(CAST(SalesProducts.UnitPrice AS NUMBER(15, 2))) AS UnitPrice,

SUM(SalesProducts.LineTotal) AS LineTotal
FR OM
Document.Sales.Products AS SalesProducts
WHERE
SalesProducts.LineTotal > ¶meter

GROUP BY
SalesProducts.Product

ORDER BY
LineTotal ASC

Profile
#6
Interested
Points:: 0
Joined:: Sep 30, 2020

Yes it works but there is a little thing;

TrueUnitPrice and MyUnitPrice below;

Profile
#7
Administrator
Points:: 0
Joined:: Oct 3, 2019

Mesut,

please upload dt-file here and also put the full text of your query.

Profile
#8
Interested
Points:: 0
Joined:: Sep 30, 2020

SEL ECT
SalesProducts.Product AS Product,
SUM(SalesProducts.Quantity) AS Quantity,
AVG(CAST(SalesProducts.UnitPrice as number(15,2))) AS UnitPrice,
SUM(SalesProducts.LineTotal) AS LineTotal
FR OM
Document.Sales.Products AS SalesProducts
WHERE
SalesProducts.LineTotal > ¶meter

GROUP BY
SalesProducts.Product

ORDER BY
LineTotal ASC


CommonModule->TASK4

Profile
#9
Administrator
Points:: 0
Joined:: Oct 3, 2019

Mesut,

in your case, the request text will be as follows:

Code
SELECT
SalesProducts.Product AS Product,
SUM(SalesProducts.Quantity) AS Quantity,
CAST(AVG(SalesProducts.UnitPrice) as number(12,2)) AS UnitPrice,
SUM(SalesProducts.LineTotal) AS LineTotal
FROM
Document.Sales.Products AS SalesProducts

GROUP BY
SalesProducts.Product

ORDER BY
LineTotal ASC




that is, we first get the average, and then round it up.

Profile
#10
Interested
Points:: 0
Joined:: Sep 30, 2020

Yes it works,thank you for ypur help.

What is the reason (12,2)?

Profile
#11
Administrator
Points:: 0
Joined:: Oct 3, 2019

Quote
Mesut Kahraman wrote:
What is the reason (12,2)?

This is my example, you can do it like this: NUMBER(15,2)

The first digit is the length of the integer part of the number after rounding, the second digit is the length of the fractional part.

Profile
#12
Interested
Points:: 0
Joined:: Sep 30, 2020

Okey thank you!

Profile
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)



© 1C LLC. All rights reserved
1C Company respects the privacy of our customers and visitors
to our Web-site.