Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
IF Exists (
select 1 where month(getdate()) IN (1,3,5,7,8,10,12)
)


i am not getting the solution for the error which this code is generting, can any one help me.
Shiv
Posted
Comments
Sandeep Mewara 18-Aug-10 8:20am    
What error?
shivtk 18-Aug-10 8:53am    
Incorrect syntax near ')'. but all openings and closing of braces are correct

u can use this if it not comming

SQL
CREATE FUNCTION [dbo].[ufn_GetDaysInMonth] ( @pDate    DATETIME )
RETURNS INT
AS
BEGIN
    RETURN CASE WHEN MONTH(@pDate) IN (1, 3, 5, 7, 8, 10, 12) THEN 31
                WHEN MONTH(@pDate) IN (4, 6, 9, 11) THEN 30
                ELSE CASE WHEN (YEAR(@pDate) % 4    = 0 AND
                                YEAR(@pDate) % 100 != 0) OR
                               (YEAR(@pDate) % 400  = 0)
                          THEN 29
                          ELSE 28
                     END
           END
END
GO
 
Share this answer
 
Comments
shivtk 18-Aug-10 8:52am    
i don wan in functions, I wan it in procedures
This at least works for me...
SQL
if exists(select 1 where month(getdate()) IN (1,3,5,7,8,10,12))
begin
  select 'Exists'
end
else
begin
  select 'Don''t exists'
end
 
Share this answer
 
Comments
shivtk 18-Aug-10 9:08am    
Thanks it works

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900