Click here to Skip to main content
15,905,915 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created the following store procedure. but when i run it arises the following error :
"Msg 241, Level 16, State 1, Procedure sp_backupManpowerCollection, Line 6
Conversion failed when converting date and/or time from character string.
"
The store procedure is as follows :
Create proc sp_backupManpowerCollection
@ATTFromDate datetime,
@ATTToDate datetime,
@Location nvarchar(50)
as
INSERT INTO tblBacManpoweCollection
SELECT EmpCode, ATTdate, LineCode,LineName,DesigCode,Designation,CompanyName,UnitName,DeptName,SecName,InHour,
InMin,OutHour,OutMin,Location,Counter,TotalOTHour,DayFlag,ProcessTime FROM tblManpowerCollection
WHERE ATTdate between '@ATTFromDate' and '@ATTToDate' and Location='@Location'
delete tblManpowerCollection where ATTdate between '@ATTFromDate' and '@ATTToDate' and Location=@Location
Posted
Comments
[no name] 10-Sep-13 5:50am    
http://dba.stackexchange.com/questions/7967/how-to-include-a-datetime-parameter-within-a-stored-procedure-along-with-string

Remove the single-quotes for Date parameters(@ATTFromDate & @ATTToDate)
 
Share this answer
 
In the WHERE clause, you shouldn't use single quotes for your datetime parameters.

Try this:
Create proc sp_backupManpowerCollection
@ATTFromDate datetime,
@ATTToDate datetime,
@Location nvarchar(50)
as
INSERT INTO tblBacManpoweCollection
SELECT EmpCode, ATTdate, LineCode,LineName,DesigCode,Designation,CompanyName,UnitName,DeptName,SecName,InHour,
InMin,OutHour,OutMin,Location,Counter,TotalOTHour,DayFlag,ProcessTime FROM tblManpowerCollection
WHERE ATTdate between @ATTFromDate and @ATTToDate and Location='@Location'
delete tblManpowerCollection where ATTdate between @ATTFromDate and @ATTToDate and Location=@Location 
 
Share this answer
 
Comments
Sumon562 10-Sep-13 6:47am    
Thanks for your kind response

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