【发布时间】:2020-10-22 14:50:00
【问题描述】:
SQL Server 2016 - PowerBI
我需要编写一个静态查询,该查询将在 PowerBI 中用于自动更新自己的仪表板,而不会获得任何使用我们公司预算周期(7 月 1 日至 6 月 30 日)的提示。我可以轻松地从我需要它的表,但它是我坚持的 where 子句。我需要它来查询以显示仅在 7/1/{year} - 6/30/{year} 之间完成的记录。有没有一种方法可以查询显示所有日期之间的记录
(if month(getdate()) in (1,2,3,4,5,6) then '7/1/' + year(getdate())) or else if month(getdate()) in (7,8,9,10,11,12) 然后 '7/1/' + year(dateadd(y,-1, getdate()))
和
(if month(Getdate()) in (1,2,3,4,5,6' then '6/30/' + year(getdate()) or else if month(getdate()) in ( 7,8,9,10,11,12) 然后 '6/30/' + year(datediff(y,1,getdate())))month(getdate()) in (1,2,3,4, 5,6) 然后 '7/1/' + 年(getdate()))
如果我将该代码写入查询,则在将 varchar 值“7/1/”转换为数据类型 int 时会出现错误错误。我认识到这是 / 行中的问题,并试图将 int 值附加到 varchar 但我似乎无法弄清楚如何解决这个问题。我错过了什么吗?
【问题讨论】:
标签: sql-server powerbi sql-server-2016