简体   繁体   中英

DATEADD and @Var in SQL Update Command

I want to update a time(0) column with the following command. ( SQLDataSource in VS 2015)

UPDATE       tb_reported
SET                Time = DATEADD(Hour, @Quantity, Time)
WHERE        (EmpShort = @EmpShort) AND (Date = @Date) AND (Time > @Time)

When i test the command (run query) it asks me for the values of the 4 parameters. for @Quantity i use eg "2" to add 2 hours. Then i click "OK" and get an error message regarding the format of the @Quantity parameter:

"Error Message: parameter value could not be converted from Decimal to TimeSpan"

When i use eg "2" instead of @Quantity the update runs without problems.

What can i do to fix this?

First try declaring @Quantity or lets say @Time

DECLARE @Time BIGINT();
@Time = DATEADD(Hour, '2', Time);

New SQL:

UPDATE tb_reported
SET    Time = @Time
WHERE  (EmpShort = @EmpShort) 
       AND (Date = @Date) 
       AND (Time > @Time)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM