Monday, May 14, 2012

Selecting multiple columns from a subquery

I've searched a lot, but still no chance on having a subquery to return multiple columns all at once. The following code works, but it sucks:



SELECT
(SELECT Column1 FROM dbo.fnGetItemPath(ib.Id)) AS Col1,
(SELECT Column2 FROM dbo.fnGetItemPath(ib.Id)) AS Col2,
(SELECT Column3 FROM dbo.fnGetItemPath(ib.Id)) AS Col3
FROM ItemBase ib


I actually have got no idea how to pass ib.Id to the function and get the entire Column1, Column2, Column3 columns without calling the fnGetItemPath function 3 times.



Thanks in advance





No comments:

Post a Comment