Hi
SQL
SET @frDate= "01/04" + (CASE WHEN (MONTH(GetDate())) <=3 THEN convert(varchar(4),
YEAR(getDate())-1) else "01/04" + convert(varchar(4),YEAR(getDate()) EndThanks
Hi
SET @frDate= "01/04" + (CASE WHEN (MONTH(GetDate())) <=3 THEN convert(varchar(4),
YEAR(getDate())-1) else "01/04" + convert(varchar(4),YEAR(getDate()) EndThanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vishal JoshiRank #377 · 6.7K reputationPosted Feb 1, 2024, 1:31 AM EST
Hello Ramco,
Please try the below code. it's not working due to closing bracket is missing ')'
SET @frDate= '01/04' + (CASE WHEN (MONTH(GetDate())) <=3 THEN convert(varchar(4), YEAR(getDate())-1) else '01/04' + convert(varchar(4),YEAR(getDate())) End)Thanks
Jayraj ChhayaRank #304 · 8.2K reputationPosted Feb 1, 2024, 1:27 AM EST
The syntax error is caused by the incorrect usage of double quotes (
") instead of single quotes (') to enclose the string literals in the code. In SQL, string literals should be enclosed in single quotes.DECLARE @frDate VARCHAR(150) SET @frDate = '01/04/' + (CASE WHEN (MONTH(GetDate())) <= 3 THEN CONVERT(varchar(4), YEAR(GETDATE()) - 1) ELSE '01/04/' + CONVERT(varchar(4), YEAR(GETDATE())) END) PRINT @FrDateBy replacing the double quotes with single quotes, the syntax error is resolved.
Sachin SinghRank #66 · 26.2K reputationPosted Feb 1, 2024, 1:34 AM EST
Check this
DECLARE @frDate VARCHAR(10); SET @frDate = '01/04' + (CASE WHEN MONTH(GETDATE()) <= 3 THEN CONVERT(VARCHAR(4), YEAR(GETDATE()) - 1) ELSE CONVERT(VARCHAR(4), YEAR(GETDATE())) END); SELECT @frDate AS Result;Tuhin PaulRank #7 · 71.9K reputationPosted Feb 2, 2024, 9:57 AM EST
SET @frDate = '01/04' + CASE WHEN MONTH(GETDATE()) <= 3 THEN CONVERT(VARCHAR(4), YEAR(GETDATE()) - 1) ELSE '01/04' + CONVERT(VARCHAR(4), YEAR(GETDATE())) END;Replaced double quotes with single quotes for string literals.