Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 IF ERROR

Author  Topic 

carla
Starting Member

12 Posts

Posted - 2011-01-12 : 12:39:21
DECLARE @year as int
DECLARE @month as int
set @month = month(Dateadd(month,2,getdate())

IF month(getdate())= 12
BEGIN
set @year = year(getdate())+ 1
END
ELSE
BEGIN
set @year = year(getdate())
END

print @year
print @month

SELECT * FROM tblDominio where month(dtmDominioFechaVencimiento)= month and year(dtmDominioFechaVencimiento) > DateAdd(month,3,getdate())





HELLO, im getting this error "Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'IF'."
but im lost and I dont know what Im missing, could u help me?


carla

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-12 : 12:44:11
you've unclosed braces in set. it should be

set @month = month(Dateadd(month,2,getdate()))

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2011-01-12 : 12:44:38
You are missing a parenthesis:
set @month = month(Dateadd(month,2,getdate()))

EDIT: Too slow. :(
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-12 : 12:45:36
i dont think the below condition is right

year(dtmDominioFechaVencimiento) > DateAdd(month,3,getdate())

can you explain what you're trying to do

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

carla
Starting Member

12 Posts

Posted - 2011-01-12 : 13:03:50
Thank you very mucho for your answers, What I'm trying to check on a table all the domains that expire in the next 3 months, thats why im using the select for...

carla
Go to Top of Page

carla
Starting Member

12 Posts

Posted - 2011-01-12 : 13:06:14
Thank you very much!! for your answers, What I'm trying to check on a table all the domains that expire in the next 3 months, thats why im using the select for...

carla


quote:
Originally posted by visakh16

i dont think the below condition is right

year(dtmDominioFechaVencimiento) > DateAdd(month,3,getdate())

can you explain what you're trying to do

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





carla
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-12 : 13:07:36
then use where like

SELECT * FROM tblDominio where dtmDominioFechaVencimiento >= dateadd(dd,datediff(dd,0,getdate()),0) and dtmDominioFechaVencimiento < dateadd(mm,datediff(mm,0,getdate())+3,0)+1


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

carla
Starting Member

12 Posts

Posted - 2011-01-12 : 13:29:52
thnks for your help! =) have a nice day!

quote:
Originally posted by visakh16

then use where like

SELECT * FROM tblDominio where dtmDominioFechaVencimiento >= dateadd(dd,datediff(dd,0,getdate()),0) and dtmDominioFechaVencimiento < dateadd(mm,datediff(mm,0,getdate())+3,0)+1


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





carla
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-12 : 13:31:34
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -