Questions tagged [outer-apply]
65 questions
0
votes
1 answer
distinct result by entire table when using cross apply on json and order by with case
I need to order my result by value from dictionary that stored as JSON in my table that equals a parameter.
In order to get it I'm using case on my order by to check if the value from the dictionary match the parameter.
After ordering the table I…

TProgram
- 5
- 2
0
votes
2 answers
Get the latest entry time using SQL if your result returns two different time, should I use cross or outer apply?
So I want to use datediff for two tables that I'm doing a join on. The problem is if I filter by a unique value, it returns two rows of result. For example:
select *
from [internalaudit]..ReprocessTracker with (nolock)
where packageID =…

learning coding
- 3
- 4
0
votes
1 answer
Filldown with outerapply
My source data is following
declare @dim as table
(
name varchar(10),period int
)
insert into @dim
select * from
(
values
('a', 202001),('a', 202002),('a', 202003),('a', 202004),
('a', 202005),('a', 202006),('a',…

smpa01
- 4,149
- 2
- 12
- 23
0
votes
1 answer
Failed to initialize sqlcmd library with error number -2147467259. - XML Column
I keep getting this error
Failed to initialize sqlcmd library with error number -2147467259
when I try to execute the following SQL code. This is a normal query and not through SQL Server Agent.
declare @SQL varchar(8000)
set @SQL = 'select…

Daniel
- 45
- 2
- 8
0
votes
0 answers
How to use SQL Server apply in typeorm
For a project I'm assigned to I have to alter a typeorm querybuilder to incorporate an "outer apply".
I could not find any support in typeorm for this.
I've looked for ways to do this by a join and a sub-query in the "on" of the join but the amount…

Kasper Jan Mooijman
- 186
- 4
- 16
0
votes
2 answers
How to use Outer Apply in oracle while converting from SQL Server
I am trying to convert a code which is written in SQL to oracle and it is using outer apply in it. But for some reason the outer apply is not working in oracle. I am using oracle 12c. The code which i am converting is:
select * from FROM table1…

Aswin Ajai
- 11
- 2
0
votes
1 answer
Outer Reference Error When Using Multiple Outer References
So I have this Query that was working well, but I needed to use the Factory Std Cost in a few other areas, so instead of calling the function multiple times I put it in an Outer Apply. However it doesn't seem to be working now. I'm getting the…

Dizzy49
- 1,360
- 24
- 35
0
votes
1 answer
Show TOP 1 considering where condition if present -SQL query
I have a case where I am using a OUTER APPLY query as below
OUTER APPLY (
SELECT TOP 1 CUSTOMER_CATEGORY
FROM [UX_VW_CUSTOMER_DETAILS] UVFS
WHERE UVFS.CUSTOMER_ID = ss.CUSTOMER_ID
) SFD
But I have new requirement where OUTER APPLY…

vmb
- 2,878
- 15
- 60
- 90
0
votes
1 answer
How to transpose rows in a table to columns (using outer apply, dynamic query )?
I have an Order Table and a OrderRow table in MS-SQL DB.
OrderNO *(Order)*
--------
100
101
102
Product Qty **(OrderRow)**
---- ---
Item1 25
Item2 50
Item3 3
Item4 10
----- n items
I want to write a select query…

Happiness
- 21
- 5
0
votes
1 answer
Postgre equivalent of MSSQL outer apply
The below code works fine with MSSQL. Any suggestion on how to translate this to Postgre?
;with mySource as (
SELECT 1050
LineID, 1 SeqNo, NULL Val
UNION SELECT 1050 LineID, 2
SeqNo, NULL Val
UNION SELECT 1050 LineID, 3
SeqNo, 'ABC' Val
UNION…

user13158095
- 3
- 3
0
votes
1 answer
Outer apply takes a long time when it contains string compare in it
I have a query:
with cte as
(
//some select statement
)
select -
// also some code here
from cte a
outer apply
(select top 1 position,traffic,tags,url,Domain,Load_Date,trend_date
from cte b
where b.Date_ID<=a.Date_ID…

Kaja
- 2,962
- 18
- 63
- 99
0
votes
2 answers
SQL: left join vs CASE subquery - which is more efficient
Which one do you guys think is more efficient (less load)?
SELECT t1.a,
(CASE
WHEN t1.p=1 THEN t2.g
WHEN t1.p=2 THEN t3.g
END) as v
FROM t1
LEFT JOIN t2 ON t1.x=t2.x
LEFT JOIN t3 ON t1.y=t3.y
OR
SELECT
t1.a, t2.v
FROM t1
outer apply…

Raheel Hasan
- 5,753
- 4
- 39
- 70
0
votes
1 answer
SQL Server Outer Apply Query Optimization
I have two tables - Table A and Table B.
Table A has 121,903 rows. Table B has only 95 rows.
I need to join Table A with Table B such that I will get first row of Table B which have matching rows with Table A order by sort criteria.
I am using…

developer
- 1,401
- 4
- 28
- 73
0
votes
0 answers
How to add dynamic outer apply in SQL Statement?
I have a task.
Basically I am selecting from table.
I want to outer apply (which means execute some code for each row) based on dynamic number coming form different table.
In Other words, I want to have dynamic number of outer apply.
Example :…

user123456
- 2,524
- 7
- 30
- 57
0
votes
1 answer
T SQL Adress Table with the same Company need latest Contact
i got an Address Table with Primary and Secondary Company locations, example:
ADDRESSES:
ID CompanyName AdressType MainID Location
1 ExampleCompany H 0 Germany
2 ExampleCompany N …

Noones
- 3
- 2