Click here to Skip to main content
16,010,392 members
Home / Discussions / Database
   

Database

 
GeneralRe: SQL server nested tables or what? [modified] Pin
Rob Graham21-Sep-06 14:43
Rob Graham21-Sep-06 14:43 
QuestionOne more question Pin
iskaza21-Sep-06 15:12
iskaza21-Sep-06 15:12 
AnswerRe: One more question Pin
Rob Graham21-Sep-06 17:36
Rob Graham21-Sep-06 17:36 
QuestionRe: One more question Pin
iskaza22-Sep-06 3:00
iskaza22-Sep-06 3:00 
GeneralDesign question - returning varying results Pin
Judah Gabriel Himango21-Sep-06 5:47
sponsorJudah Gabriel Himango21-Sep-06 5:47 
GeneralRe: Design question - returning varying results Pin
Eric Dahlvang21-Sep-06 6:42
Eric Dahlvang21-Sep-06 6:42 
GeneralRe: Design question - returning varying results Pin
Judah Gabriel Himango21-Sep-06 8:35
sponsorJudah Gabriel Himango21-Sep-06 8:35 
GeneralRe: Design question - returning varying results Pin
Eric Dahlvang21-Sep-06 11:23
Eric Dahlvang21-Sep-06 11:23 
Even though they are slow, cursors are sometimes the best option. Especially when compared to running a hundred queries.
You could dynamically create an SQL statement by doing something like this:
create procedure GetFooInfo
as 
DECLARE @nFooID int,@cType varchar(50),@cSQL varchar(2000)

set @cSQL = ''

DECLARE  fooBase CURSOR FOR 
SELECT distinct Type
FROM fooTable

OPEN fooBase 
FETCH NEXT FROM fooBase INTO @cType 
WHILE @@FETCH_STATUS = 0
BEGIN
	if len(@cType) > 0
	     set @cSQL = @cSQL + ' LEFT JOIN ' + @cType + ' ON fooTable.FooID = ' +  @cType + '.FooInheritorID '
      	FETCH NEXT FROM fooBase INTO @cType 

END

CLOSE fooBase 
DEALLOCATE fooBase 
exec('SELECT * FROM fooTable ' + @cSQL)
go


ps. This is what I did to set things up to be similar to your description:
CREATE TABLE fooTable (
	FooID int IDENTITY (1, 1) NOT NULL,
	Type varchar (50),
	FooBaseInfo varchar(50) 
) ON [PRIMARY]
GO

insert into fooTable (Type,FooBaseInfo) values ('','this is a basic foo')
insert into fooTable (Type,FooBaseInfo) values ('FooInheritor1','FooInheritor1 foo 1')
insert into fooTable (Type,FooBaseInfo) values ('FooInheritor2','FooInheritor2 foo 1')
insert into fooTable (Type,FooBaseInfo) values ('FooInheritor3','FooInheritor3 foo 1')
insert into fooTable (Type,FooBaseInfo) values ('FooInheritor4','FooInheritor4 foo 1')
insert into fooTable (Type,FooBaseInfo) values ('FooInheritor2','FooInheritor2 foo 2')
insert into fooTable (Type,FooBaseInfo) values ('FooInheritor4','FooInheritor4 foo 2')
insert into fooTable (Type,FooBaseInfo) values ('FooInheritor4','FooInheritor4 foo 3')
insert into fooTable (Type,FooBaseInfo) values ('FooInheritor2','FooInheritor2 foo 3')
insert into fooTable (Type,FooBaseInfo) values ('FooInheritor4','FooInheritor4 foo 4')

CREATE TABLE FooInheritor1 (
	FooInheritorID int,
	Foo1Specific varchar(50)  
) ON [PRIMARY]
INSERT INTO FooInheritor1 select FooID,'Specific to 1' as Specific FROM fooTable where Type = 'FooInheritor1'

CREATE TABLE FooInheritor2 (
	FooInheritorID int,
	Foo2Specific varchar(50)  
) ON [PRIMARY]
INSERT INTO FooInheritor2 select FooID,'Specific to 2' as Specific FROM fooTable where Type = 'FooInheritor2'

CREATE TABLE FooInheritor3 (
	FooInheritorID int,
	Foo3Specific varchar(50)  
) ON [PRIMARY]
INSERT INTO FooInheritor3 select FooID,'Specific to 3' as Specific FROM fooTable where Type = 'FooInheritor3'


CREATE TABLE FooInheritor4 (
	FooInheritorID int,
	Foo4Specific varchar(50) 
) ON [PRIMARY]
INSERT INTO FooInheritor4 select FooID,'Specific to 4' as Specific FROM fooTable where Type = 'FooInheritor4'
GO





--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters

GeneralRe: Design question - returning varying results [modified] Pin
Eric Dahlvang22-Sep-06 3:26
Eric Dahlvang22-Sep-06 3:26 
GeneralRe: Design question - returning varying results Pin
Judah Gabriel Himango22-Sep-06 5:38
sponsorJudah Gabriel Himango22-Sep-06 5:38 
GeneralRe: Design question - returning varying results Pin
Eric Dahlvang22-Sep-06 6:17
Eric Dahlvang22-Sep-06 6:17 
GeneralRe: Design question - returning varying results Pin
Judah Gabriel Himango22-Sep-06 6:28
sponsorJudah Gabriel Himango22-Sep-06 6:28 
GeneralRe: Design question - returning varying results Pin
Scott Serl21-Sep-06 7:49
Scott Serl21-Sep-06 7:49 
GeneralRe: Design question - returning varying results Pin
Judah Gabriel Himango21-Sep-06 8:39
sponsorJudah Gabriel Himango21-Sep-06 8:39 
GeneralRe: Design question - returning varying results Pin
Scott Serl21-Sep-06 9:03
Scott Serl21-Sep-06 9:03 
GeneralRe: Design question - returning varying results Pin
Judah Gabriel Himango21-Sep-06 10:00
sponsorJudah Gabriel Himango21-Sep-06 10:00 
GeneralRe: Design question - returning varying results Pin
Scott Serl21-Sep-06 10:27
Scott Serl21-Sep-06 10:27 
GeneralRe: Design question - returning varying results Pin
Judah Gabriel Himango21-Sep-06 18:01
sponsorJudah Gabriel Himango21-Sep-06 18:01 
QuestionRowFilter and Dataset Pin
Itanium21-Sep-06 2:28
Itanium21-Sep-06 2:28 
AnswerRe: RowFilter and Dataset Pin
Stephan Pilz21-Sep-06 21:06
Stephan Pilz21-Sep-06 21:06 
QuestionVisual Query Builder Pin
BadKarma21-Sep-06 2:09
BadKarma21-Sep-06 2:09 
QuestionSQL Server CURSOR Pin
choorakkuttyil21-Sep-06 2:07
choorakkuttyil21-Sep-06 2:07 
AnswerRe: SQL Server CURSOR Pin
_AK_21-Sep-06 3:34
_AK_21-Sep-06 3:34 
AnswerRe: SQL Server CURSOR Pin
Eric Dahlvang21-Sep-06 3:45
Eric Dahlvang21-Sep-06 3:45 
QuestionSQL server 2005 express edition Pin
NituC21-Sep-06 0:20
NituC21-Sep-06 0:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.