Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I am getting a date parameter value as '4-1-2009' from front end. Now I want to make it as 4-1-2010

I am trying like below.But it is showing error.
SQL
ALTER PROCEDURE [dbo].[SP_EMP]                    

 @STARTDATE DATETIME,   --4-1-2009  from front end

 @ENDDATE DATETIME,
   
 @STARTDATE2 DATETIME, 
 
 SET  @STARTDATE2=DATEADD(yy, 1, @STARTDATE)

AS                      
BEGIN 

SELECT EMPNAME FROM EMP WHERE JOINDATE>@STARTDATE2

----//  SOME JOINS //----

END

How can I do this?
Please tell me.

Regards,
N.SRIRAM
Posted
Updated 19-Jan-11 20:16pm
v5
Comments
TweakBird 20-Jan-11 1:41am    
Edited for code formating.
justinonday 20-Jan-11 2:10am    
paste here your front end code ,how you passing date???/
check date format...

This is first question answer..



Declare @D as DateTime
Set @D='4-1-2009'
Declare @E DateTime
SET @E=DATEADD(yy, 1, @D)



This is Second ,check your syntax
ALTER PROCEDURE [dbo].[SP_EMP]

@STARTDATE DATETIME, --4-1-2009 from front end

@ENDDATE DATETIME,

@STARTDATE2 DATETIME




AS
BEGIN
SET @STARTDATE2=DATEADD(yy, 1, @STARTDATE)
SELECT EMPNAME FROM EMP WHERE JOINDATE>@STARTDATE2

----// SOME JOINS //----

END
 
Share this answer
 
v3
Comments
Dalek Dave 20-Jan-11 3:32am    
Removed 'BIG' tags, it makes the answer look ugly.
justinonday 20-Jan-11 4:13am    
Thanks again Mr.Delek Dave
I think you are aware that you can't declare variable in SQL without it's data type.

As you've declare
Declare @D
This should be like
Declare @D datetime
So you should change your script like below

Declare @D datetime
Set @D='4-1-2009'
Declare @E datetime
SET @E =@D
 
Share this answer
 

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