开发者

SQL Script Help, combine two queries into one

开发者 https://www.devze.com 2023-01-05 16:19 出处:网络
I was wondering if these two queries could be combined into a single query? Query 1: to get the @guidID to be plugged into Query 2:

I was wondering if these two queries could be combined into a single query?

Query 1: to get the @guidID to be plugged into Query 2:

DECLARE @guidID uniqueIdentifier
    SET @guidID = (SELECT guidID FROM dbo.table1 WHERE IntID = 1) 

Query 2: retrieves a combined table from a function and table1

SELECT o.guidID, IntID, Title, func.Name 
  FROM dbo.t开发者_开发问答able1 o
 INNER JOIN dbo.func1(o.guidID) func ON func.guidID = o.guidID
 WHERE IntID = 1

func1 takes in a guidID object Returns a table of (guidID, IntID

Thanks for any help, this is as far as I've gotten, which give me the data that I need but in two separate queries.


SQL Server 2005+ has CROSS APPLY

SELECT t.guidID, IntID, Title, func.Name 
  FROM
     dbo.table1 o
     CROSS APPLY
     dbo.func1(o.guidID) func
 WHERE IntID = 1

Edit: won't work... However, assuming you have one row for IntID = 1, you can also cross join for other DBMS/older SQL Servers

SELECT t.guidID, IntID, Title, func.Name 
  FROM
     dbo.table1 o
    CROSS JOIN
    dbo.func1(o.guidID) func
 WHERE IntID = 1

0

精彩评论

暂无评论...
验证码 换一张
取 消