C# de>不是有效日期,无论排序规则如何。如果您想说参数替换在字符串中不起作用,您是对的。但从你写答案的方式来看,这很难理解。也许你应该编辑它? #region Validate and prepare parameters i
C# de>不是有效日期,无论排序规则如何。如果您想说参数替换在字符串中不起作用,您是对的。但从你写答案的方式来看,这很难理解。也许你应该编辑它? #region Validate and prepare parameters i,c#,linq,datetime,linq-to-sql,executequery,C#,Linq,Datetime,Linq To Sql,Executequery,de>不是有效日期,无论排序规则如何。如果您想说参数替换在字符串中不起作用,您是对的。但从你写答案的方式来看,这很难理解。也许你应该编辑它? #region Validate and prepare parameters if (month > 12) { throw new ArgumentException("Value of 'month' could not be greater than 12.");
de>不是有效日期,无论排序规则如何。如果您想说参数替换在字符串中不起作用,您是对的。但从你写答案的方式来看,这很难理解。也许你应该编辑它?
#region Validate and prepare parameters
if (month > 12)
{
throw new ArgumentException("Value of 'month' could not be greater than 12.");
}
int yearEnd = year;
int monthEnd = 0;
if (month != 12)
{
monthEnd = month + 1;
}
else
{
monthEnd = 1;
yearEnd = year + 1;
}
#endregion
MyModelDataContext context = new MyModelDataContext();
string sql =
@"select SUM(ORDERQTY * MULTIPLIER) AS VOL_USD
from Executions with (nolock)
where TRANSACTTIME >= '{0}-{1}-01 00:00:00'
and TRANSACTTIME < '{2}-{3}-01 00:00:00'
and MTCONTEXT in (5,6)
and ORDERQTY > 0
AND SOURCE = 'INTMT'
and LEFT(SYMBOL, 3) = 'USD'";
decimal usd___Sum = context.ExecuteQuery<decimal>(sql, year, month, yearEnd, monthEnd).First();
var startDate=new DateTime(year,month,1);
var endDate=new DateTime(yearEnd,monthEnd,1);
string sql =
@"select SUM(ORDERQTY * MULTIPLIER) AS VOL_USD
from Executions with (nolock)
where TRANSACTTIME >= {0}
and TRANSACTTIME < {1}
and MTCONTEXT in (5,6)
and ORDERQTY > 0
AND SOURCE = 'INTMT'
and LEFT(SYMBOL, 3) = 'USD'";
decimal usd___Sum = context.ExecuteQuery<decimal>(sql, startDate,endDate).First();
string sql =
@"select SUM(ORDERQTY * MULTIPLIER) AS VOL_USD
from Executions with (nolock)
where TRANSACTTIME >= DATETIMEFROMPARTS({0},{1},1,0,0,0,0)
..."
exec sp_executesql
N'select SUM(ORDERQTY * MULTIPLIER) AS VOL_USD
from Executions with (nolock)
where TRANSACTTIME >= ''@p0-@p1-01 00:00:00''
and TRANSACTTIME < ''@p2-@p3-01 00:00:00'''
,N'@p0 int,@p1 int,@p2 int,@p3 int'
,@p0=2013,@p1=9,@p2=2013,@p3=10
where TRANSACTTIME >= {0} and and TRANSACTTIME < {1}
...
context.ExecuteQuery<decimal>(sql, new DateTime(year, month, 1), new DateTime(yearEnd, monthEnd, 1))
where TRANSACTTIME >= convert(datetime, {0} + '-' + {1} + '-01 00:00:00')
and TRANSACTTIME < convert(datetime, {2} + '-' + {3} + '-01 00:00:00')
...
context.ExecuteQuery<decimal>(sql, year.ToString(), month.ToString(), yearEnd.ToString(), monthEnd.ToString())