Sql server date1的语法错误
我试过了,检查一下Sql server date1的语法错误,sql-server,Sql Server,我试过了,检查一下 SELECT FactOrders.TerritoryKey , FactOrders.DistributorKey , FactOrders.ItemKey , SUM(FactOrders.UnitQty)as Quantity , SUM(FactOrders.GrossValue) as Gross_Value FROM FactOrders WHERE FactOrders.TerritoryKey = @
SELECT FactOrders.TerritoryKey ,
FactOrders.DistributorKey ,
FactOrders.ItemKey ,
SUM(FactOrders.UnitQty)as Quantity ,
SUM(FactOrders.GrossValue) as Gross_Value
FROM FactOrders
WHERE FactOrders.TerritoryKey = @TerritoryKey and
FactOrders.DistributorKey = @DistributorKey and
FactOrders.DateKey >=CInt(Format(Paramters!@Date1.Value,"yyyyMMdd")) and
FactOrders.DateKey <= @Date2 AND
FactOrders.LineType = 'ORDER'
GROUP BY FactOrders.TerritoryKey , FactOrders.DistributorKey ,FactOrders.ItemKey
ORDER BY FactOrders.TerritoryKey , FactOrders.DistributorKey ,FactOrders.ItemKey
@Date1看起来像一个变量,但您是否在任何地方定义了它?为什么要访问属性?@Date1是我的ms sql报表编写器中的参数。它是日期类型参数。我想将其转换为intiger。@Dumindaaturaliyapathegama Date1=2017-01-31表示您需要转换为的基础int@Chanukya我想将2016年5月21日转换为20160521。因为在数据库中,日期用作整数。但在参数部分,我想将其用作日期类型。@Chanukya现在在将varchar值5/21/2016转换为数据类型int时给出转换失败,错误245
SELECT FactOrders.TerritoryKey ,
FactOrders.DistributorKey ,
FactOrders.ItemKey ,
SUM(FactOrders.UnitQty)as Quantity ,
SUM(FactOrders.GrossValue) as Gross_Value
FROM FactOrders
WHERE FactOrders.TerritoryKey = @TerritoryKey and
FactOrders.DistributorKey = @DistributorKey and
---- FactOrders.DateKey >=CInt(Format(Paramters!@Date1.Value,"yyyyMMdd")) and
CONVERT(varchar(8),CAST(@date1 AS DATE),112)
FactOrders.DateKey <= @Date2 AND
FactOrders.LineType = 'ORDER'
GROUP BY FactOrders.TerritoryKey , FactOrders.DistributorKey ,FactOrders.ItemKey
ORDER BY FactOrders.TerritoryKey , FactOrders.DistributorKey ,FactOrders.ItemKey