Tuesday, February 12, 2013 4:00 PM
My statement below is failing withthe below:
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'SELECT'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '<'.
Msg 102, Level 15, State 1, Line 10
What is wrong with the below statement?IF Select DATENAME(dw,GETDATE()) = 'Monday'
Update statement is here
Tuesday, February 12, 2013 4:02 PMModerator
You don't need SELECT in that statement, e.g.
IF DATENAME(weekday, CURRENT_TIMESTAMP) = 'Monday'
update statement here
For every expert, there is an equal and opposite expert. - Becker's Law
- Marked As Answer by Iric WenModerator Wednesday, February 20, 2013 8:52 AM
Tuesday, February 12, 2013 4:05 PMModerator
Tuesday, February 12, 2013 4:15 PM
The short answer is that you do not need the SELECT. The right answer is that you do not know how to write SQL and are still writing BASIC. SQL is a declarative language, so we do not use IF-THEN flow control or loops. We do not write code that is language dependent like you did. We also have the ANSI/ISO Standard CURRENT_TIMESTAMP now. Here is the skeleton.
SET floob = ???
WHERE DATEPART(DW, CURRENT_TIMESTAMP)) = 1;
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking in Sets / Trees and Hierarchies in SQL
Tuesday, February 12, 2013 4:18 PM
if(datename(Dw,getdate())='Monday') begin Update statement is here
Ahsan Kabir Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread. http://www.aktechforum.blogspot.com/