Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I have to increase by 3% and round up the prices I have in a table. My script:
UPDATE tbl_products
SET Prices = CEILING(prices * 1.03, 0)
After I run the script, SQL Server Management Studio returns an error, saying:
ceiling function requires one argument.
If I use ROUND instead of CEILING, the script works great. What I'm doing wrong?
Syntax is as shown below. Ceiling() function is used to find the smallest integer value.
CEILING( number )
Here is an example.
SELECT CEILING(32.65);
Result: 33
SELECT CEILING(32.1);
Result: 33
SELECT CEILING(32);
Result: 32
SELECT CEILING(-32.65);
Result: -32
SELECT CEILING(-32);
Result: -32
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 months ago.
Improve this question
I have a bunch of alphanumeric codes stored as Nvarchar. I want to take all the codes that begin with a 1 and append .00001 onto the end of them. I tried this code
,CASE
WHEN left(1,[CASE_CODE]) = '1'
THEN concat([CASE_CODE],'.00001')
ELSE [CASE_CODE]
END as [CASE_CODE]
But I get this error message
Msg 245, Level 16, State 1, Line 2
Conversion failed when converting the nvarchar value 'PVC00595' to data type int.
Is the LEFT function converting to int for some reason?
As per the documentation, left takes a character expression followed by an integer expression. Your error is coming from left(1,[CASE_CODE]) trying to convert CASE_CODE into an integer expression (since it is the second argument).
You want left([CASE_CODE], 1) (reversed arguments) instead.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I want to convert this bigint for Ex: 637194307500000000 using Microsoft sql server. I have tried
SELECT DATEADD(S, 637194307500000000, '19700101')
I am getting arithmetic overflow error.
SQL Server cannot represent a time that large. If, perhaps you mean 6,371,943,075 seconds, then you could switch to minutes instead:
SELECT DATEADD(MINUTE, 6371943075 / 60, '19700101')
This produces the result 2171-12-02 08:11:00.000, which itself seems a bit unlikely.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I try to apply WHERE AND WHERE operators, but somehow AND returns an error, single WHERE for both cases works fine.
I don't feel like I made a mistake in code as well, at least not in general SQL syntax.
SELECT *
FROM dbo.flat_file
WHERE [Date] > '1/1/2020'
AND
WHERE [Deposit] > 1000
I am new to T-SQL, so I may not be aware of basic principles.
tsql printscr
There can only be one WHERE clause in a query. You try to have two. Instead just AND the second condition to the first in the first (and only) WHERE clause.
SELECT *
FROM dbo.flat_file
WHERE [Date] > '1/1/2020'
AND [Deposit] > 1000;
Side note: varchar is likely the wrong datatype for date and deposit. date and integer my be a better fit.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
Azure SQL Server 2017
Status Field Value:
1796-NM_IndiatimesMumbai_Daily has run
Statement:
PATINDEX('%[MED]%', Status COLLATE SQL_Latin1_General_CP1_CS_AS)
Returns
7
Why? I thought I was looking for an exact match on "MED" in all caps, so I would expect 0. I apparently don't have my pattern syntax correct.
Because like combined with square brackets [] searches for any character between the brackets. Is you remove the brackets
Like '%MED%'
It works asyou expect
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm trying to write a query that will update all values the values in the Values column.
This is what I've come up with:
Begin
UPDATE Order_Details
SET Value = (Value / 100) * 10
WHERE Cust_Ref = ALL
End
It doesn't work and comes up with
Incorrect syntax near keyword END
Does anyone know how to correct this?
Thanks guys! Much appreciated!!!
You don't need Where clause
UPDATE Order_Details SET Value = (Value / 100.0) * 10
You need to use Where clause only when you want to filter the records
Also Value / 100 will do a Integer division. The decimal values will not be present in result. So make either the numerator or denominator as decimal value
Example :
select 1/ 10 -- Result 0
select 1/ 10.0 -- Result 0.100000