SQL查询无法计算

时间:2018-09-07 04:00:17

标签: c# sql-server

我的SQL查询无法计算精确的OTAmount。我试图将其查询到SQL Server,查询看起来很好。我唯一要更改的是HRate变量。

decimal DR=0;
decimal HRate = 0;

if (rdSal.HasRows)
{
     rdSal.Read();
     DR = Convert.ToDecimal(rdSal.GetString(2));
     HRate = DR / 8;
}

SqlCommand cmd3 = new SqlCommand();
cmd3.Connection = con;
cmd3.CommandType = CommandType.Text;
cmd3.CommandText = "Insert Into Overtime ([EMPID],[Date],[OTMins], 
[OTAmount],[DayofWeek])Select UserID,Date,DateDiff(minute,TimeIn,TimeOut), 
(DateDiff(minute,TimeIn,TimeOut)/60.00)*1.25*"+HRate+",DayofWeek from 
UserLog where DayofWeek='Saturday' and USERID='" + val + "'AND DATE>='" + 
codatebegintxt.Text + "'AND DATE<='" + codateendtxt.Text + "'";

cmd3.ExecuteNonQuery();
con.Close();

1 个答案:

答案 0 :(得分:0)

您可以将DR更改为:

temp1<-strsplit(gsub("\\)\\)","", gsub("list\\(", "", df$aaa)), split = ",") # removing characters list( and )) and split the result
temp2 <- lapply(temp1, function(x) round(as.numeric(x),2)) # converting to numeric and rounding

data.frame(number= df$number,
      new= unlist((lapply(temp2,paste,collapse = ", "))))

  number                                      new
1      1                      10.44, 11.33, 12.33
2      2 10.33, 11.33, 12.33, 13.33, 14.33, 15.33
3      3                                    20.33
4      4                                         

DR = Convert.ToDecimal(rdSal.GetString(2), System.Globalization.CultureInfo.CurrentCulture); 而不是HRate = DR / 8.0

其他如注释中所示,您可以将其更改为:

HRate = DR / 8

,并在变量前面添加@来替换命令文本。 (希望它不会混淆)。

相关问题