Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Subquery?

Author  Topic 

Pirre0001
Starting Member

19 Posts

Posted - 2014-03-18 : 14:58:52
I use an subquery according below that will use a stored procedure. Input data to the stored procedure arrive from main sql. But it does not work. The code below is an outline to show what I mean. I want to use artid_head and artnr_head from main sql as input to my stored procedure in the subquery. SQL is much larger in practice...

Select
tblArt.artid_head,
tblBen.artnr_head,

(SELECT FIRST
STRING(ct_disp.customer) + ' / ' + (select customer.k_namn from customer where customer.k_kod =ct_disp.customer)
FROM
(SELECT
period as period,
lev_customer as customer,
qty + SUM(best - reserv) OVER (PARTITION BY artnr ORDER BY datum ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as qty
FROM
sp_get_info(artnr_head, artid_head, 1)) AS ct_disp
WHERE
ct_disp.qty < 0
ORDER BY
ct_disp.period) as cc_plan_customer

FROM
tblArt,
tblBen
WHERE
tblArt.ID = tblBen.ID

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-03-18 : 15:11:43
Not clear as to what you want. How does it not work? Error message? Unexpected results?

Please see these links:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

Pirre0001
Starting Member

19 Posts

Posted - 2014-03-18 : 15:15:42
The subquery doesn't find artnr_head, artid_head in sp_get_info(artnr_head, artid_head, 1))...

quote:
Originally posted by Lamprey

Not clear as to what you want. How does it not work? Error message? Unexpected results?

Please see these links:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Go to Top of Page
   

- Advertisement -