Computing.Net > Forums > Programming > remove a decimal or round up in sql

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

remove a decimal or round up in sql

Reply to Message Icon

Name: Adrian
Date: April 18, 2002 at 16:28:27 Pacific
Comment:

I have a problem,
I need an sql (for access) statement that will alway return the coming sunday's date from any day in the week including sunday,

can i round up in an sql statement? if i could this would be nice,
then i could do omething like,

((roundup(date()/7))*7)+1

this would would work if i could round up, but i dont think i can.

or if i could just drop the decimal somehow, and use.

(((remove decimal(date()/7))+1)*7)+1

is there any way i can do this?

any help would be greatful



Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: April 19, 2002 at 08:47:57 Pacific
Reply:

I believe that functions like this vary among the different implementations of SQL, so you'll probably have to dig thru your versions documentation.

Informix has a round function of the format:

round(number, digits)

Examples

round(24536.7654, -2) = 24500.00

round(24536.7654, 0) = 24537.00

round(24536.7654, 2) = 24536.77


Informix also has Trunc() which does truncates the digits without rounding.

I just looked in the mySQL doc and round works the same there. So maybe this is more standard than I thought.


0

Response Number 2
Name: Jim
Date: April 19, 2002 at 11:28:35 Pacific
Reply:

I'm not sure what the function is in sql. In other languages it's trunc(), or int(), or floor().

However, they way you did your roundup using the int() is not quite correct. It's pretty close, but you'll get different results in cases where date is evenly divisible by 7. I don't know if that's what your application wants or not, but there are a couple of ways to make it really round up. The easiest takes into account that the date() is going to return an integer, and you're always dividing it by 7.

(int((date()+6)/7)*7)+1

You may even want to try 6.5 to eliminate rounding errors.


0

Response Number 3
Name: adrian
Date: April 24, 2002 at 10:56:20 Pacific
Reply:

thanks for the help, i found that this doe exactly what i want,
(((Int((Date()-2)/7)+1)*7)+1)

thi will alway return the coming sunday's date.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: remove a decimal or round up in sql

No show up in taskbar with VB www.computing.net/answers/programming/no-show-up-in-taskbar-with-vb/765.html

Rounding up decimals in C? www.computing.net/answers/programming/rounding-up-decimals-in-c/7181.html

Create a Data warehouse in SQL Server 2K www.computing.net/answers/programming/create-a-data-warehouse-in-sql-server-2k/2725.html