Billy McBurnie - 1 year ago 64

SQL Question

Using SQL server, write a while loop to calculate and print the functional value of f(x) = 3x&3 -2X^2 + 15 for all odd non negative integers <= 25. ( 1, 3, 5, …23,25).

This is what I have written out so far

And this is the result I get

So theoretically I should be getting 45,640 when

`@x = 25`

What am I going wrong here?

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

You have to use `power`

function like the following

```
Declare @SUMSQUARE Integer, @x Integer
SET @X = 1
WHILE (@X <= 25)
BEGIN
SELECT @SUMSQUARE = (3*power(@X,3))-(2*power(@X,2))+15
PRINT @SUMSQUARE
SET @X = @X + 2
END
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**