I did find this post: how do I subtract values from two select statements
but I cannot get it to work on SQL-Server 2008.
I have two basic SELECT statements. No GROUP BYs or anything, just a SELECT, FROM and WHERE.
I would like to subtract one of these SELECTs from the other. Both return one row and column.
Could somebody please help?
SELECT
((SELECT Field1 AS BaseBase FROM Table1
WHERE Field2 = 'something'
AND Field3 =
(SELECT Field4 FROM SEL_Function('something','something')) as tab1)
-
((SELECT Field5 FROM SEL_Function('something','something') as tab2)
Alright I don’t think the cross apply is necessary fiddle won’t allow functions but check out this fiddle. You will want to swap out the table of the same name with the function. I think you were getting bit by a combination of alias and paren mismatches.
http://sqlfiddle.com/#!3/dc72f/13