cross-apply

Using cross apply in update statement

柔情痞子 提交于 2019-12-04 02:44:58
问题 Is it possible to use the cross apply clause in the from part of an update statement, in SQL Server 2005? 回答1: You where right, Albert. I made some tests and found that it's possible, indeed. The use is the same as in a SELECT statement. For example: UPDATE some_table SET some_row = A.another_row, some_row2 = A.another_row/2 FROM some_table st CROSS APPLY (SELECT TOP 1 another_row FROM another_table at WHERE at.shared_id=st.shared_id) AS A WHERE ... 来源: https://stackoverflow.com/questions

Get comma separated values from an xml in SQL

浪子不回头ぞ 提交于 2019-12-02 16:00:51
问题 I am calling Scalar UDF from a stored procedure to get a column value. Inside the scalar UDF I have an xml and I have to get the comma separated values of a particular node. I used Cross apply but it caused huge performance bottleneck because stored procedure is actually used to fetch reports. There is a table [Traveler] which has a field ID, BookingID(can be duplicate) and FareDetails. Inside the FareDetails we are storing the xml. The logic inside UDF is as follows : 1st Solution , Using

Mutiple columns with independent where clause - SQL Pivot?

本秂侑毒 提交于 2019-12-02 05:33:34
问题 Is it possible to take a table that is structured in the following fashion: ID Month Info1 Info2 1 1 A B 1 2 C D 1 3 E F 2 3 G H 2 4 I J That ends up into a table like this: ID JanInfo1 JanInfo2 FebInfo1 FebInfo2 MarInfo1 MarInfo2 AprInfo1 AprInfo2 1 A B C D E F NULL NULL 2 NULL NULL NULL NULL G H I J I've looked into using pivots and couldn't get them to work. I currently use CROSS APPLY table valued functions for each each month. Is there a better way to do this? Edit: Added existing query

Mutiple columns with independent where clause - SQL Pivot?

寵の児 提交于 2019-12-01 22:58:29
Is it possible to take a table that is structured in the following fashion: ID Month Info1 Info2 1 1 A B 1 2 C D 1 3 E F 2 3 G H 2 4 I J That ends up into a table like this: ID JanInfo1 JanInfo2 FebInfo1 FebInfo2 MarInfo1 MarInfo2 AprInfo1 AprInfo2 1 A B C D E F NULL NULL 2 NULL NULL NULL NULL G H I J I've looked into using pivots and couldn't get them to work. I currently use CROSS APPLY table valued functions for each each month. Is there a better way to do this? Edit: Added existing query - tried to simplify for display: -- Get the unique IDs DECLARE @PersonIds TABLE ( UploadID

Using cross apply in update statement

瘦欲@ 提交于 2019-12-01 15:40:29
Is it possible to use the cross apply clause in the from part of an update statement, in SQL Server 2005? You where right, Albert. I made some tests and found that it's possible, indeed. The use is the same as in a SELECT statement. For example: UPDATE some_table SET some_row = A.another_row, some_row2 = A.another_row/2 FROM some_table st CROSS APPLY (SELECT TOP 1 another_row FROM another_table at WHERE at.shared_id=st.shared_id) AS A WHERE ... 来源: https://stackoverflow.com/questions/7492797/using-cross-apply-in-update-statement

Using CROSS APPLY for more than one column

廉价感情. 提交于 2019-12-01 10:53:04
Day #3 with SQL Server. I am trying to combine 2 columns of delimited data into one output from a Table Valued Function. Here is my data: I would like the data to be processed and placed into a table in the following format: I am currently trying to use this CROSS APPLY TSQL statement, but I don't know what I'm doing. USE [Metrics] INSERT INTO dbo.tblSplitData(SplitKey, SplitString, SplitValues) SELECT d.RawKey, c.*, e.* FROM dbo.tblRawData d CROSS APPLY dbo.splitstringcomma(d.DelimitedString) c, dbo.splitstringcomma(d.DelimitedValues) e My research on CROSS APPLY has broad context, and I don

Entity Framework and CROSS/OUTER APPLY

三世轮回 提交于 2019-12-01 03:38:36
I want to create some test cases for Entity Framework queries that surely generate SQL commands that contain CROSS APPLY or OUTER APPLY operators. Could someone show typical scenarios where these kind of SQL queries appear? In LINQ 2 SQL this always results in an APPLY : from t1 in tab1 from t2 in tab2.Where(t2 => t2.SomeCol == t1.SomeCol).Take(1) select new { t1, t2 } In EF this will either fail, or also result in an APPLY (I don't know which one). This is a correlated join which requires an APPLY on the SQL side. Something like this would generate an outer apply: var ListLocation = from d in

Entity Framework and CROSS/OUTER APPLY

血红的双手。 提交于 2019-11-30 23:53:01
问题 I want to create some test cases for Entity Framework queries that surely generate SQL commands that contain CROSS APPLY or OUTER APPLY operators. Could someone show typical scenarios where these kind of SQL queries appear? 回答1: In LINQ 2 SQL this always results in an APPLY : from t1 in tab1 from t2 in tab2.Where(t2 => t2.SomeCol == t1.SomeCol).Take(1) select new { t1, t2 } In EF this will either fail, or also result in an APPLY (I don't know which one). This is a correlated join which

Using CROSS APPLY for more than one column

笑着哭i 提交于 2019-11-30 20:02:58
问题 Day #3 with SQL Server. I am trying to combine 2 columns of delimited data into one output from a Table Valued Function. Here is my data: I would like the data to be processed and placed into a table in the following format: I am currently trying to use this CROSS APPLY TSQL statement, but I don't know what I'm doing. USE [Metrics] INSERT INTO dbo.tblSplitData(SplitKey, SplitString, SplitValues) SELECT d.RawKey, c.*, e.* FROM dbo.tblRawData d CROSS APPLY dbo.splitstringcomma(d.DelimitedString

CROSS/OUTER APPLY in MySQL

最后都变了- 提交于 2019-11-27 05:19:17
I need to use CROSS APPLY in MySQL (EC2 RDS MySQL instance). Looks like MySQL doesn't recognise the CROSS APPLY Syntax. Can someone help me please? Here's the query. SELECT ORD.ID ,ORD.NAME ,ORD.DATE ,ORD_HIST.VALUE FROM ORD CROSS APPLY ( SELECT TOP 1 ORD_HISTORY.VALUE FROM ORD_HISTORY WHERE ORD.ID = ORD_HISTORY.ID AND ORD.DATE <= ORD_HISTORY.DATE ORDER BY ORD_HISTORY.DATE DESC ) ORD_HIST Your closest direct approximation is a join with a correlated sub-query as the predicate. SELECT ORD.ID ,ORD.NAME ,ORD.DATE ,ORD_HISTORY.VALUE FROM ORD INNER JOIN ORD_HISTORY ON ORD_HISTORY.<PRIMARY_KEY> =