Click here to Skip to main content
15,908,013 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello There,
I tried to run this query but it didn't work for me.
C#
@StartDt NVARCHAR(25),
@Period INT 

UPDATE CROS_L SET DUE5 = bal_amt WHERE ABS(CONVERT(DATETIME,@StartDt,103)- due_date) >= @Period AND due_date IS NOT NULL;


Exception:
SQL
Implicit conversion from data type datetime to float is not allowed. Use the CONVERT function to run this query.


Need Suggestion
Best Regards
Posted
Updated 17-Mar-13 19:44pm
v3
Comments
S R JHALA 18-Mar-13 1:55am    
what is Period here and why you check >= @Period
please write what you exactly looking for
Mayank Topiwala 18-Mar-13 2:00am    
Period is any integer value say 30
so the query update the table if difference between two dates is greater than or equal to 30.

SQL
@StartDt NVARCHAR(25),
@Period INT

UPDATE CROS_L SET DUE5 = bal_amt WHERE ABS(datediff(day,CONVERT(DATETIME,@StartDt,103), due_date)) >= @Period AND due_date IS NOT NULL;

Happy Coding!
:)
 
Share this answer
 
v2
Comments
Mayank Topiwala 18-Mar-13 1:58am    
It shows incorrect syntax near '>'.
Aarti Meswania 18-Mar-13 2:02am    
see updated solution
Mayank Topiwala 18-Mar-13 2:13am    
Thank You!
Aarti Meswania 18-Mar-13 2:15am    
most welcome!
Glad to help u! :)
SQL
DECLARE 
 @StartDt DATETIME = '2013-03-11 11:22:52.053'
,@Period INT = 1 
,@due_date DATETIME = '2013-03-18 11:22:52.053'


--This will Update as it will return 7 as DATEDIFF which is greater than period which is 1 over here
UPDATE CROS_L SET DUE5 = bal_amt WHERE DATEDIFF(D,@StartDt,@due_date) >= @Period AND @due_date IS NOT NULL;



SET @Period = 10 

--This will not Update as it will return 7 as DATEDIFF which is not greater than period which is 10 over here
UPDATE CROS_L SET DUE5 = bal_amt WHERE DATEDIFF(D,@StartDt,@due_date) >= @Period AND @due_date IS NOT NULL;
 
Share this answer
 
Comments
Mayank Topiwala 18-Mar-13 2:13am    
Thank You!

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