Query is executing in sqldbx but not in SSRS ( Visual Studio 2010 ) - sql-server

My query is as follows :
SELECT LBrCode, PrdAcctId, EffFromDate, ACTUALDATE, ACTUALDATENEW, IdealBalDate, IdealBal,
SancDate, TotSancLimit, ExpDate, NoOfInstl, InstlstartDt, InstlAmt, DpDate, TotalDpArrived, TotalDpAllowed, NEWDATE, IdealBalNew
, sum(z.IdealBalNew) OVER (partition BY z.LBrCode, z.PrdAcctId, datepart(MM, z.NEWDATE), datepart(yyyy, z.NEWDATE) ORDER BY LBrCode, PrdAcctId, NEWDATE) NEWESTBALANCE
FROM (
SUB QUERY
) z
--GROUP BY z.LBrCode, z.PrdAcctId, z.EffFromDate
ORDER BY LBrCode, PrdAcctId, EffFromDate
In the above query , When i comment the " sum(z.IdealBalNew) OVER " columns , the query is accepted in SSRS Report dataset . But with sum(z.IdealBalNew) OVER column it gives error . Error is : Incorrect syntax near "order" , Incorrect syntax near "z" , Microsoft sql error : 102. Same query executes properly in sqldbx database.
Any issue regarding " sum() OVER partition order by " not being supported by SSRS Visual Studio 2010 ?

Any issue regarding " sum() OVER partition order by " not being
supported by SSRS Visual Studio 2010 ?
No, there is no such known issue. Probably you have a typo or some other difference in your SSRS code.

Related

QueryDSL predicate with Spring data repository - convert timestamp to varchar in WHERE clause

I am writing Java code fetching data from SQL Server DB. I am using Spring Data repository and QueryDSL Predicate with findAll(Predicate ..)
I need to implement in the following WHERE clause :
WHERE CONVERT(nvarchar(24),myTable.Time_Stamp,21) > "some date as string"
It works as SQL in SQL Server Studio.
Here is how I define the Predicate in QueryDSL:
BooleanExpression nextEvents = Expressions.stringTemplate("CONVERT({0}, {1}, {2})","nvarchar(24)", myTable.timeStamp, "21").gt("some date as string");
I get the following exception:
Incorrect syntax near '#P0'.
Here are the where caluse of the query and the bindings that Hibernate produces:
where CONVERT(?, unifiedent0_.Time_Stamp, ?)>? order by unifiedent0_.Time_Stamp asc offset 0 rows fetch next ? rows only
: binding parameter [1] as [VARCHAR] - [nvarchar(24)]
: binding parameter [2] as [VARCHAR] - [21]
: binding parameter [3] as [VARCHAR] - [2022-09-20 09:56:32.077-113]
It all looks correct to me : 3 ? signs and bindings that I expect to see.
What is wrong with the queryDSL expression?
Thank you.
I decided to ditch QueryDSL and use JPQL.
It did the job.
The Query is:
#Query("SELECT uem FROM UnifiedEntityMessage uem "
+ "WHERE convert(nvarchar(24),uem.timeStamp,21) + '-' + trim(str(uem.id)) > :lastSentCompositeKey "
+ "and uem.pId in :pids "
+ "and uem.timeStamp < :before "
+ "and uem.type <> :type")

report “Window query not supported” when using state_window in TDengine

I'm using state_window syntax in TDengine database.
My SQL statement is:
select t.*
from (
select ts,
tbname as app_id,
tenant_name,
queue_code,
task_name,
sum(allocated) as allocated
from yarn
where ts > now - 6m
partition by ts,tbname,tenant_name,queue_code,task_name
) t
partition by ts, app_id, tenant_name, queue_code, task_name
state_window((CASE WHEN allocated > 100 THEN 1 ELSE 0 END));
Then I encountered an error report:
DB error: Window query not supported, since the result of subquery not
include valid timestamp column
I don't particularly understand its meaning, and how to fix the problem.

Sum Partition by order by in SQL Server [duplicate]

I get an execution error in following SQL script:
SELECT TOP 1 PERCENT
a.accode, a.voucherdate, a.credit, a.Debit,
SUM(a.Debit) OVER (ORDER BY [a.accode],[a.voucherdate]) AS rdr
FROM
VoucherMain AS a
ORDER BY
a.accode, a.voucherdate
Error message
Incorrect syntax near 'order'
Can anyone tell me what's wrong with my syntax?
The problem is that you need SQL Server 2012 and above. Okay, I added the "and above" for future visitors, but compare 2008 OVER CLAUSE with 2012 OVER CLAUSE.
The 2008 version has this important note:
When used in the context of a ranking window function, <ORDER BY
Clause> can only refer to columns made available by the FROM clause.
An integer cannot be specified to represent the position of the name
or alias of a column in the select list. <ORDER BY Clause> cannot be
used with aggregate window functions.
In SQL Server 2008, you can only use the OVER clause to partition aggregate functions, not apply an order:
Ranking Window Functions
< OVER_CLAUSE > :: =
OVER ( [ PARTITION BY value_expression , ... [ n ] ]
< ORDER BY_Clause> )
Aggregate Window Functions
< OVER_CLAUSE > :: =
OVER ( [ PARTITION BY value_expression , ... [ n ] ] )
Note that there's no <ORDER BY Clause> for the aggregates.

Spotfire: My SQL Queries are not running in Spotfire while it runs in SQL Server Management Studio?

Shows the following error-
External error:
Incorrect syntax near the keyword 'Use'.
Incorrect syntax near ')'.
Submitted query:
Use VPDC
exec vpdc.pa.spMaybeDrop #AllSOText
SELECT DISTINCT dt.UnitID, dt.MainPlatform, dt.SBU, dt.country,dt.HighestContract, pa.fnStripLeadingZeroes(dSO.ServiceOrderNumber) ServiceOrderNumber, dso.StatusOrderNumber, dso.StatusOrderNumberText, ServiceOrderText, ServiceOrderLongText, Cast(BasicStart as date) BasicStart, orderType
into #AllSOText
from aa.vwSAPServiceOrders_OneLinePerServiceOrder dSO
inner join aa.vwTurbines dt on dt.UnitId = dso.UnitId
While it works fine in SQL Server Management Studio.
Remove the "Use VPDC". This is specific to management studio to change context to a database. In client apps this is specified in the connection string or you can write the script with database context, as below:
exec vpdc.pa.spMaybeDrop #AllSOText
SELECT DISTINCT dt.UnitID, dt.MainPlatform, dt.SBU, dt.country,dt.HighestContract, pa.fnStripLeadingZeroes(dSO.ServiceOrderNumber) ServiceOrderNumber, dso.StatusOrderNumber, dso.StatusOrderNumberText, ServiceOrderText, ServiceOrderLongText, Cast(BasicStart as date) BasicStart, orderType
into #AllSOText
from vpdc.aa.vwSAPServiceOrders_OneLinePerServiceOrder dSO
inner join vpdc.aa.vwTurbines dt on dt.UnitId = dso.UnitId

Issue with Window Function in SQL Server 2008 R2

I get an execution error in following SQL script:
SELECT TOP 1 PERCENT
a.accode, a.voucherdate, a.credit, a.Debit,
SUM(a.Debit) OVER (ORDER BY [a.accode],[a.voucherdate]) AS rdr
FROM
VoucherMain AS a
ORDER BY
a.accode, a.voucherdate
Error message
Incorrect syntax near 'order'
Can anyone tell me what's wrong with my syntax?
The problem is that you need SQL Server 2012 and above. Okay, I added the "and above" for future visitors, but compare 2008 OVER CLAUSE with 2012 OVER CLAUSE.
The 2008 version has this important note:
When used in the context of a ranking window function, <ORDER BY
Clause> can only refer to columns made available by the FROM clause.
An integer cannot be specified to represent the position of the name
or alias of a column in the select list. <ORDER BY Clause> cannot be
used with aggregate window functions.
In SQL Server 2008, you can only use the OVER clause to partition aggregate functions, not apply an order:
Ranking Window Functions
< OVER_CLAUSE > :: =
OVER ( [ PARTITION BY value_expression , ... [ n ] ]
< ORDER BY_Clause> )
Aggregate Window Functions
< OVER_CLAUSE > :: =
OVER ( [ PARTITION BY value_expression , ... [ n ] ] )
Note that there's no <ORDER BY Clause> for the aggregates.

Resources