SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Need an example of a nested view
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

itmaster
Starting Member

16 Posts

Posted - 08/13/2013 :  08:28:14  Show Profile  Reply with Quote
Hi,
They want me to write a nested view and I canot find an example anywhere. Can someomne show me one please.

Thnk you

SwePeso
Patron Saint of Lost Yaks

Sweden
30108 Posts

Posted - 08/13/2013 :  08:31:15  Show Profile  Visit SwePeso's Homepage  Reply with Quote
create view dbo.View1 AS select 1 as ColumnName
Go
create view dbo.View2 as select ColumnName, 2 * columnname AS TwiceColumnName from dbo.view1
go

select * from dbo.view2
go



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

itmaster
Starting Member

16 Posts

Posted - 08/13/2013 :  09:45:11  Show Profile  Reply with Quote
Thanks for the help and this ias my fault, but this is nto what I mean. They call it view but it isn't. It is is something like this:
select *
from t1
Inner join
(
Select Max(val)...
Inner join
(
SQL statement
Union
SQL statement
) vi1
....
This is not exact code, because that is what I am looking for I do not know how to do the nested vi1s?
the code I
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3557 Posts

Posted - 08/13/2013 :  09:48:45  Show Profile  Reply with Quote
Do you mean something like this?
CREATE TABLE #A (id INT, val FLOAT);
CREATE TABLE #B (id INT, val FLOAT);

SELECT
	*
FROM
(
	SELECT id, MAX(val) AS MaxValA FROM #A 
) a
INNER JOIN
(
	SELECT id, MAX(val) AS MaxValB FROM #B
	UNION ALL
	SELECT id, MAX(val) FROM #A
) b ON a.id = b.id;


DROP TABLE #A;
DROP TABLE #b;
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30108 Posts

Posted - 08/13/2013 :  09:49:55  Show Profile  Visit SwePeso's Homepage  Reply with Quote
You mean a derived table?


Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4608 Posts

Posted - 08/13/2013 :  10:11:44  Show Profile  Reply with Quote
That is, as Peso said, a derived table. Sometimes is it also called an inline-view.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000