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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Convert varchar to Datetime

Author  Topic 

anandbe21
Starting Member

4 Posts

Posted - 2009-10-05 : 21:51:52
Hi All,

i need to convert my Datevalue datatype to Varchar this is my Query here i need to modify here


select @RemDays =datediff(dd,@dateOfReporting,'2009-08-28') from tbl_leavedetails,tbl_LeaveReporting where tbl_leavedetails.LeaveId =tbl_LeaveReporting.leaveId


set @qrystr1 ='update tbl_LeaveStatistics set AlreadyUsed = (AlreadyUsed - ''+(Convert(varchar,@RemDays,102))+'') where Flag =@flag+'

set @qrystr2 ='update tbl_leavedetails set NoofDays = (NoofDays - ''+@RemDays+'') where LeaveId =''+@leaveId+'''

here @RemDays value comming here is Datetime when keeping this variable value in
@qrystr1,@qrystr2 here i need to Convert from Datetime value to varchar .convert function i need todo. How to append and send this variable value during cast or convert like ''+Cast(@RemDays as Datetime)+'' any help regarding this

Regards
ANAND


tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-10-06 : 00:47:39
I don't understand why dynamic SQL is being used here. Why can't you just do this instead:

update tbl_leavedetails
set NoofDays = NoofDays - @RemDays
where LeaveId = @leaveId

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -