Eroor while using below CASE STATEMENT related to DATE [closed] - sql

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 4 months ago.
Improve this question
Below QUOTE_REGISTER_DATE datatype is varchar2, when running below script it's giving error.
select CASE WHEN TO_CHAR(TO_DATE(QUOTE_REGISTER_DATE, 'DD-MON-YYYY', 'DY')) = 'SAT' THEN 0
ELSE SAT_SUN_COUNT
END SAT_SUN_COUNT
from tablename;

You've got an error in the function, write it like this:
select CASE WHEN TO_CHAR(TO_DATE(QUOTE_REGISTER_DATE, 'DD-MON-YYYY'), 'DY') = 'SAT' THEN 0 ELSE SAT_SUN_COUNT END SAT_SUN_COUNT
from tablename
And for another time, add the error you get to the question, we cannot just guess what is wrong. For this question, it was obvious.
[Edit]: removed the second of the '))'. Thanks for the comment.

Related

Using SQL BETWEEN [closed]

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 8 months ago.
Improve this question
Please help me fix this error.
SELECT
*
FROM activity_log_admins
WHERE query_date BETWEEN 4th-June-2022 AND 10th-June-2022
But am receiving this error.
#1054 - Unknown column '4th' in 'where clause'
Assuming query_date is a type of datetime, Try
SELECT
*
FROM activity_log_admins
WHERE query_date BETWEEN '2202-06-04' AND '2202-06-10'

Convert timestamp to int [closed]

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 10 months ago.
Improve this question
I need to convert timestamp to int.
Basically I am looking to convert 2022-04-20 00:21:21:123 into 20220420.
I am trying below the below way but not working.
select usernumber, cast(format(created_date,'YYYYMMDD') as int)
from table1;
note that 'Y' and 'D' must be lowercase and your dataype isn't timestamp that's datetime type.
select usernumber, cast(FORMAT(created_date,'yyyyMMdd') as int)
from table1;

Wrongly closed SQL parentheses [closed]

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'm fairly new at writing SQL commands so I don't exactly know where I'm going wrong here. I closed all the parentheses, but I still get the following error message:
Syntax error: Expected ")" but got keyword AND at [18:5]
Code:
goals as (
select sum(cast(goal as int64)) as goal
from seed.seed_ads_goals
goal_total
and extract(month from [daterange_start]) = month
)
Any hints?
WHERE Clause is missing :
select sum(cast(goal as int64)) as goal
from seed.seed_ads_goals as goal_total
where extract(month from [daterange_start]) = month

Oracle : date not valid for month specified [closed]

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 am trying to insert a record in oracle using toad and getting the error. As seen below i am using the TO_DATE FUNCTION
date not valid for month specified. I am using TO_DATE function.
INSERT ALL
INTO MGR.TRACK_RECORD (VALUE_DATE,PERFORMANCE,DATE_CREATED,LAST_MODIFIED,CREATED_BY_ID,LAST_MODIFIED_BY_ID,IS_ESTIMATE)
VALUES (TO_DATE('2011/11/31 21:02:44', 'yyyy/mm/dd hh24:mi:ss'),4.10,SYSDATE,SYSDATE,96,338,0)
SELECT * FROM dual;
The error is clear in that it states the date you provided (the day part, the 31st) is not valid for the month you provided (11, November). November only has 30 days.

SQL - Multiple Replace [closed]

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 8 years ago.
Improve this question
what i try to do is a multiple replace of an variable string.
but the problem that nothing happend.
i canĀ“t figured out what is wrong in the code:
can someone give me hand with this pls?
here is the sql code:
SET #HTML = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(#EMAILBODY2SEND,
'#%LoginUser%#',#Name),
'#%Number%#',#Number),
'#%classification%#',#classification),
'#%Phone%#',#Phone,
'#%Date#',#Date)
Hope following query can make your life easier by not nesting too many parentheses.
SET #HTML = #EMAILBODY2SEND;
SELECT #HTML = REPLACE(#Html, P, R)
FROM (VALUES ('#%LoginUser%#',#Name),
('#%Number%#',#Number),
('#%classification%#',#classification),
('#%Phone%#',#Phone),
('#%Date#',#Date)
) AS T(P, R)