0

I'm developing a bank system for Garry's Mod (GLua) using sql for it. I want to create a "profit" that adds a percentage to every player every minute: The sql query is this one:

UPDATE 
     darkrp_player 
SET 
     bank = bank * "..multiplier

This is what it returns when running that query on DBBrowser:

no such function: floor: UPDATE darkrp_player SET bank = floor(bank * 1.25)

multiplier var is (profit/100) + 1 profit is another var

So my problem is that everytime I run that query, every bank row is full of decimals, example:

profit = 25
--before query:
'bank' = 2
--after query:
'bank' = 2.5

My question is: How can I set floor to the value I'm setting to 'bank'? I could get everybody's 'bank' value and set it one by one, but that would be really really complicated... So, i'm looking something like

UPDATE 
     darkrp_player 
SET 
     bank = floor(bank * "..multiplier..")"

I'm sorry if you haven't understood something, you can ask me whatever related to my problem, I'll be glad to answer you. THANKS!

Hogan
  • 69,564
  • 10
  • 76
  • 117

2 Answers2

0

If there is no FLOOR function on that built-in server, try this:

SELECT CAST('67.896' AS int),  CAST('5.57' AS int)
Denis Reznik
  • 964
  • 5
  • 10
  • The problem is that I don't want to SELECT, I want to SET – Alex Paredes Sep 14 '16 at 18:43
  • 1
    @AlexParedes -- this is an example -- try it if it works use it in the set. – Hogan Sep 14 '16 at 18:43
  • @AlexParedes UPDATE darkrp_player SET bank = CAST(CAST(bank * "..multiplier AS decimal) AS int) – Denis Reznik Sep 14 '16 at 18:45
  • It worked, thank you! I tried CONVERT but didn't work, thanks for showing me CAST function! – Alex Paredes Sep 14 '16 at 18:53
  • @AlexParedes due to the fact that you post this question to the SQL Server topic first, I suppose that maybe you use a really old version of SQL Server, that is why I propose this solution. As for SQLite, looks like the query can a bit simpler: CAST('67.896' AS int). I will update the answer accordingly. – Denis Reznik Sep 14 '16 at 19:00
-2
--declaring variable table for example
declare @x table (value real)

--inserting some dummy values in variable table
insert into @x (value)
select '12.45'
union
select '56.789'

select * from @x

--updating variable table values using floor function
--floor function Returns the largest integer less than or equal to the specified numeric expression
update @x set value = floor(value)

select * from @x
DatabaseCoder
  • 2,004
  • 2
  • 12
  • 22