Re: Cross apply doesn't require a UDF

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



While CROSS APPLY is really not document well (hope they update it soon), there are plenty of examples on the web that demonstrate use of the APPLY operator with table expressions. A quick search on CROSS APPLY shows a few on the first page that demonstrate that, here is one:
http://weblogs.sqlteam.com/jeffs/archive/2007/10/18/sql-server-cross-apply.aspx

Yes, indeed it is a powerful operator, see this example:

CREATE TABLE Foo (
keycol INT PRIMARY KEY,
x INT,
y INT);

INSERT INTO Foo VALUES(1, 10, 5), (2, 11, 4), (3, 8, 3);

SELECT keycol, x, y, z
FROM Foo
CROSS APPLY (SELECT x + y AS z) AS C;

/*

keycol x y z
----------- ----------- ----------- -----------
1 10 5 15
2 11 4 15
3 8 3 11

*/

--
Plamen Ratchev
http://www.SQLStudio.com
.



Relevant Pages

  • [GIT PULL] one kbuild fix
    ... Full patch below. ... Subject: kbuild: soften modpost checks when doing cross builds ... int opt; ...
    (Linux-Kernel)
  • RE: xml nodes and user defined function
    ... create table test(id int identity(1,1), doc varchar) ... cross apply doc.nodesas t ... Doc is in xml format. ... But it still complains about "Incorrect syntax near ')'". ...
    (microsoft.public.sqlserver.xml)
  • Re: strange case of void main
    ... > Just for curiosity. ... > an int, but I came cross with the following ... (Unnessecary code is snipped) ...
    (comp.lang.c)
  • Restricting children processes
    ... I want to fork a number of children processes but I also want to ... cross some value. ... int max_children = 50; ...
    (comp.unix.programmer)
  • Iterated Encryption in RSA
    ... She should cross a little if ... Latif's glove isn't following. ... We incorporate them, then we enough shift Ibraheem and Jeanette's ... Plenty of grey surviving summary dares knowledges apart from ...
    (sci.crypt)