SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to make hierarchical structure


How to make hierarchical structure

Author
Message
masoud_sedighy
masoud_sedighy
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 14
I have 5 tables and query has returned from these tables.

Table1=tldDocuments
{

Docid (pk, Auto number)
Title (text)
Doc (text)
}

Docid Docno

1 doc-001
2 doc-005
1


Table2-tblTransmittalNo

{
Transid (pk, Auto number)

Tansmittalno (text)
}

Transid transmittalno

1 tt-0002




Table3=tblTransmittals
{
Docid (fk to tblDocuments, number)

Transid (fk to tblTransmittalNo, number)
}

Docid Transid
1 1
2 1




Tables 4= tblTranstoCon

{

TransmittalToConId (pk,auto number)

TransmittaltoCon (text)

}

TransmittalToConId TransmittaltoCon
1 CON-0003
2 CON-0005
3 CON-0007



Table 5

{
Docid (number,PK,fk to tblTransmittals)
Transid (number,PK, fk to tblTransmittals)
TransToCon (number,PK,fk to tblTranstoCon)
}

Docid Transid transmittalToConid
1 1 1
2 1 2
1 1 3


Table 5 has 2 fks (combine fields) to table3 because I have for same (docid,transid) different tranmittaltoConId

I have designed tables 2 years ago I do not know it is completely correct or no and I have entered data to the tables, if design of tables also has problem please help.

But now I like to make a hierarchical structure for the returned data with below query with adding fields parenntid,position



Query:


SELECT tldDocuments.Docno, tblTransmittalNo.Tansmittalno, tblTranstoCon.TransmittaltoCon
FROM tblTranstoCon INNER JOIN ((tblTransmittalNo INNER JOIN (tldDocuments INNER JOIN tblTransmittals ON tldDocuments.Docid = tblTransmittals.Docid) ON tblTransmittalNo.Transid = tblTransmittals.Transid) INNER JOIN tblDocTrantoCon ON (tblTransmittals.Transid = tblDocTrantoCon.Transid) AND (tblTransmittals.Docid = tblDocTrantoCon.DocID)) ON tblTranstoCon.TransmittalToConId = tblDocTrantoCon.TransToCon;


DocNo TransmittalNo TransmittaltoCon

Doc-001 tt-0002 con-0003

Doc-001 tt-0002 con-0007

Doc-005 tt-0002 con-0005







ID PARENT POSITION OPTION

1 0 0 DOC-0001

2 1 0 TT-0002

3 0 1 DOC-0005

4 2 1 CON-0007

5 3 0 TT-0002

6 5 0 CON-0003
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25881 Visits: 17511
Hi and welcome to the forums. In order to help we will need a few things:

1. Sample DDL in the form of CREATE TABLE statements
2. Sample data in the form of INSERT INTO statements
3. Expected results based on the sample data

Please take a few minutes and read the first article in my signature for best practices when posting questions.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
masoud_sedighy
masoud_sedighy
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 14
thanks,

i try to provide create table and insert value statements

tblDocuments:

USE [EDMS]
GO

/****** Object: Table [dbo].[tblDocuments] Script Date: 06/25/2013 23:44:17 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[tblDocuments](
[Originator] [nvarchar](255) NOT NULL,
[Document Type] [nvarchar](255) NOT NULL,
[Unit] [nvarchar](255) NOT NULL,
[EQ-IN Identify/Material Code] [nvarchar](255) NOT NULL,
[Sequential No] [nvarchar](50) NULL,
[DocId] [int] IDENTITY(17314,1) NOT NULL,
[DocumentNo] [nvarchar](200) NOT NULL,
[TITLE] [nvarchar](255) NOT NULL,
CONSTRAINT [PK_tblDocuments_1] PRIMARY KEY CLUSTERED
(
[DocId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO






tbltransmittalNo

USE [EDMS]
GO

/****** Object: Table [dbo].[tbltransmittalNo] Script Date: 06/25/2013 23:56:44 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[tbltransmittalNo](
[TRANSMITTAL] [nvarchar](200) NOT NULL,
[TransID] [int] IDENTITY(8858,1) NOT NULL,
[RevDATE] [datetime] NULL,
[Originator Code] [nvarchar](50) NULL,
[Originator Location] [nvarchar](50) NULL,
[Recipient Code] [nvarchar](50) NULL,
[Recipient Location] [nvarchar](50) NULL,
[Serial No] [nvarchar](50) NULL,
[Subject] [nvarchar](50) NULL,
[Originator] [nvarchar](50) NULL,
[Reciever] [nvarchar](50) NULL,
[Attention] [nvarchar](50) NULL,
CONSTRAINT [PK_tbltransmittalNo_1] PRIMARY KEY CLUSTERED
(
[TransID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO






tblTransmittalls

USE [EDMS]
GO

/****** Object: Table [dbo].[tblTransmittalls] Script Date: 06/25/2013 23:57:57 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[tblTransmittalls](
[DocID] [int] NOT NULL,
[REV] [nvarchar](255) NULL,
[TransId] [int] NOT NULL,
[Pages] [nvarchar](50) NULL,
[Class] [nvarchar](50) NULL,
[Size] [nvarchar](50) NULL,
[PurposeofIssue] [nvarchar](50) NULL,
[DefaultForDocument] [bit] NULL,
CONSTRAINT [PK_tblTransmittalls_1] PRIMARY KEY CLUSTERED
(
[DocID] ASC,
[TransId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[tblTransmittalls] WITH CHECK ADD CONSTRAINT [FK_tblTransmittalls_tblDocuments] FOREIGN KEY([DocID])
REFERENCES [dbo].[tblDocuments] ([DocId])
GO

ALTER TABLE [dbo].[tblTransmittalls] CHECK CONSTRAINT [FK_tblTransmittalls_tblDocuments]
GO

ALTER TABLE [dbo].[tblTransmittalls] WITH NOCHECK ADD CONSTRAINT [FK_tblTransmittalls_tbltransmittalNo] FOREIGN KEY([TransId])
REFERENCES [dbo].[tbltransmittalNo] ([TransID])
GO

ALTER TABLE [dbo].[tblTransmittalls] NOCHECK CONSTRAINT [FK_tblTransmittalls_tbltransmittalNo]
GO

ALTER TABLE [dbo].[tblTransmittalls] ADD CONSTRAINT [DF_tblTransmittalls_DefaultForDocument] DEFAULT ((0)) FOR [DefaultForDocument]
GO





tblTranstoCon

USE [EDMS]
GO

/****** Object: Table [dbo].[tblTranstoCon] Script Date: 06/25/2013 23:59:14 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[tblTranstoCon](
[TRANSMITtoConId] [int] IDENTITY(2212,1) NOT NULL,
[TRANSMITtoCon] [nvarchar](50) NOT NULL,
[Oldtransmittocon] [nvarchar](255) NULL,
[RevDATE] [datetime] NULL,
[Originator] [nvarchar](255) NULL,
[old Recipient] [nvarchar](255) NULL,
[Recipient] [nvarchar](255) NULL,
[Serial No] [nvarchar](255) NULL,
[Subject] [nvarchar](255) NULL,
[Type Code] [nvarchar](255) NULL,
[Copies] [nvarchar](255) NULL,
[Remark] [nvarchar](255) NULL,
CONSTRAINT [PK_tblTranstoCon_1] PRIMARY KEY CLUSTERED
(
[TRANSMITtoConId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO






USE [EDMS]
GO

/****** Object: Table [dbo].[tblDocTranstoCon] Script Date: 06/26/2013 00:00:17 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[tblDocTranstoCon](
[DocID] [int] NOT NULL,
[TransId] [int] NOT NULL,
[TRANSMITtoConId] [int] NOT NULL,
CONSTRAINT [PK_tblDocTranstoCon] PRIMARY KEY CLUSTERED
(
[DocID] ASC,
[TransId] ASC,
[TRANSMITtoConId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[tblDocTranstoCon] WITH CHECK ADD CONSTRAINT [FK_tblDocTranstoCon_tblTransmittalls] FOREIGN KEY([DocID], [TransId])
REFERENCES [dbo].[tblTransmittalls] ([DocID], [TransId])
GO

ALTER TABLE [dbo].[tblDocTranstoCon] CHECK CONSTRAINT [FK_tblDocTranstoCon_tblTransmittalls]
GO

ALTER TABLE [dbo].[tblDocTranstoCon] WITH CHECK ADD CONSTRAINT [FK_tblDocTranstoCon_tblTranstoCon] FOREIGN KEY([TRANSMITtoConId])
REFERENCES [dbo].[tblTranstoCon] ([TRANSMITtoConId])
GO

ALTER TABLE [dbo].[tblDocTranstoCon] CHECK CONSTRAINT [FK_tblDocTranstoCon_tblTranstoCon]
GO


---------------------------------------------------------------


INSERT INTO [EDMS].[dbo].[tblDocuments]
([Originator]
,[Document Type]
,[Unit]
,[EQ-IN Identify/Material Code]
,[Sequential No]
,[DocumentNo]
,[TITLE])
VALUES
('Abad','dw','100','1441','001','doc-001','test1'),
('paya','dw','140','1441','005','doc-005','test2')


GO


INSERT INTO [EDMS].[dbo].[tbltransmittalNo]
([TRANSMITTAL]
,[RevDATE]
,[Originator Code]
,[Originator Location]
,[Recipient Code]
,[Recipient Location]
,[Serial No]
,[Subject]
,[Originator]
,[Reciever]
,[Attention])
VALUES
('tt-0002', null,null,null,null,null,null,null,null,null,null)
GO
-------------------------------------------------------------------
INSERT INTO [EDMS].[dbo].[tblTransmittalls]
([DocID]
,[REV]
,[TransId]
,[Pages]
,[Class]
,[Size]
,[PurposeofIssue]
,[DefaultForDocument])
VALUES
(1,'0',1,null,null,null,null,null),
(2,'0',1, null,null,null,null,null)

GO
------------------------------------------------------------

INSERT INTO [EDMS].[dbo].[tblTranstoCon]
([TRANSMITtoCon]
,[Oldtransmittocon]
,[RevDATE]
,[Originator]
,[old Recipient]
,[Recipient]
,[Serial No]
,[Subject]
,[Type Code]
,[Copies]
,[Remark])
VALUES
('con-0003',null,null,null,null,null,null,null,null,null,null),

('con-0005',null,null,null,null,null,null,null,null,null,null),

('con-0007',null,null,null,null,null,null,null,null,null,null)


GO
INSERT INTO [EDMS].[dbo].[tblDocTranstoCon]
([DocID]
,[TransId]
,[TRANSMITtoConId])
VALUES
(1,1,1),
(1,1,3),
(2,1,2)

GO




Query:


SELECT dbo.tblDocuments.DocumentNo, dbo.tbltransmittalNo.TRANSMITTAL, dbo.tblTranstoCon.TRANSMITtoCon
FROM dbo.tblDocuments INNER JOIN
dbo.tblTransmittalls ON dbo.tblDocuments.DocId = dbo.tblTransmittalls.DocID INNER JOIN
dbo.tbltransmittalNo ON dbo.tblTransmittalls.TransId = dbo.tbltransmittalNo.TransID INNER JOIN
dbo.tblDocTranstoCon ON dbo.tblTransmittalls.DocID = dbo.tblDocTranstoCon.DocID AND
dbo.tblTransmittalls.TransId = dbo.tblDocTranstoCon.TransId INNER JOIN
dbo.tblTranstoCon ON dbo.tblDocTranstoCon.TRANSMITtoConId = dbo.tblTranstoCon.TRANSMITtoConId

-------------------------------------------------------------

This query returns below data:

DocNo TransmittalNo TransmittaltoCon
Doc-001 tt-0002 con-0003
Doc-001 tt-0002 con-0007
Doc-005 tt-0002 con-0005


I like to make a query that returns also below data:

ID PARENT POSITION OPTION
1 0 0 DOC-0001
2 1 0 TT-0002
3 0 1 DOC-0005
4 2 1 CON-0007
5 3 0 TT-0002
6 5 0 CON-0003
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25881 Visits: 17511
Thanks for posting ddl and sample data. There seems to be something a little wrong with your sample data. It will not run because it violates some of your foreign key constraints. If I recreate the tables and data without the constraints your query returns no rows.

In general it is easier if you don't have the database specified in the objects so it easier for use to work with. Also, you can get your code in a nice little scrollable window by using the IFCode shortcuts (over on the left when you are posting).

I think you are pretty close to having the information needed to figure this out.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
masoud_sedighy
masoud_sedighy
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 14
i checked my ddl again and it works and it returns sample data
This query returns below data:



DocNo TransmittalNo TransmittaltoCon
Doc-001 tt-0002 con-0003
Doc-001 tt-0002 con-0007
Doc-005 tt-0002 con-0005



I like to make a query that returns also below data:

ID PARENT POSITION OPTION
1 0 0 DOC-0001
2 1 0 TT-0002
3 0 1 DOC-0005
4 2 1 CON-0007
5 3 0 TT-0002
6 5 0 CON-0003



it seams my question is clear, i recieve docno with transmittalno from main office and then t get tranmittaltoconNo by my self and distribute these documents, getting number for docno,transmittalno is not my job just i can get tranmittaltoconNo so sometimes i dispatch one document that i have received with transmittalno to 3 or 6 contractor.
so i have for same (docid,transid) different transmittaltoConID , if the design of tables has problem please help?
also please help how i can make hierarchical structure query with parent and position.

thanks in advanced.
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25881 Visits: 17511
No your sample data does not work as posted. Here is the script after removing all the references to EDMS.


CREATE TABLE [dbo].[tblDocuments](
[Originator] [nvarchar](255) NOT NULL,
[Document Type] [nvarchar](255) NOT NULL,
[Unit] [nvarchar](255) NOT NULL,
[EQ-IN Identify/Material Code] [nvarchar](255) NOT NULL,
[Sequential No] [nvarchar](50) NULL,
[DocId] [int] IDENTITY(17314,1) NOT NULL,
[DocumentNo] [nvarchar](200) NOT NULL,
[TITLE] [nvarchar](255) NOT NULL,
CONSTRAINT [PK_tblDocuments_1] PRIMARY KEY CLUSTERED
(
[DocId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

/****** Object: Table [dbo].[tbltransmittalNo] Script Date: 06/25/2013 23:56:44 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[tbltransmittalNo](
[TRANSMITTAL] [nvarchar](200) NOT NULL,
[TransID] [int] IDENTITY(8858,1) NOT NULL,
[RevDATE] [datetime] NULL,
[Originator Code] [nvarchar](50) NULL,
[Originator Location] [nvarchar](50) NULL,
[Recipient Code] [nvarchar](50) NULL,
[Recipient Location] [nvarchar](50) NULL,
[Serial No] [nvarchar](50) NULL,
[Subject] [nvarchar](50) NULL,
[Originator] [nvarchar](50) NULL,
[Reciever] [nvarchar](50) NULL,
[Attention] [nvarchar](50) NULL,
CONSTRAINT [PK_tbltransmittalNo_1] PRIMARY KEY CLUSTERED
(
[TransID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

/****** Object: Table [dbo].[tblTransmittalls] Script Date: 06/25/2013 23:57:57 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[tblTransmittalls](
[DocID] [int] NOT NULL,
[REV] [nvarchar](255) NULL,
[TransId] [int] NOT NULL,
[Pages] [nvarchar](50) NULL,
[Class] [nvarchar](50) NULL,
[Size] [nvarchar](50) NULL,
[PurposeofIssue] [nvarchar](50) NULL,
[DefaultForDocument] [bit] NULL,
CONSTRAINT [PK_tblTransmittalls_1] PRIMARY KEY CLUSTERED
(
[DocID] ASC,
[TransId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[tblTransmittalls] WITH CHECK ADD CONSTRAINT [FK_tblTransmittalls_tblDocuments] FOREIGN KEY([DocID])
REFERENCES [dbo].[tblDocuments] ([DocId])
GO

ALTER TABLE [dbo].[tblTransmittalls] CHECK CONSTRAINT [FK_tblTransmittalls_tblDocuments]
GO

ALTER TABLE [dbo].[tblTransmittalls] WITH NOCHECK ADD CONSTRAINT [FK_tblTransmittalls_tbltransmittalNo] FOREIGN KEY([TransId])
REFERENCES [dbo].[tbltransmittalNo] ([TransID])
GO

ALTER TABLE [dbo].[tblTransmittalls] NOCHECK CONSTRAINT [FK_tblTransmittalls_tbltransmittalNo]
GO

ALTER TABLE [dbo].[tblTransmittalls] ADD CONSTRAINT [DF_tblTransmittalls_DefaultForDocument] DEFAULT ((0)) FOR [DefaultForDocument]
GO

/****** Object: Table [dbo].[tblTranstoCon] Script Date: 06/25/2013 23:59:14 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[tblTranstoCon](
[TRANSMITtoConId] [int] IDENTITY(2212,1) NOT NULL,
[TRANSMITtoCon] [nvarchar](50) NOT NULL,
[Oldtransmittocon] [nvarchar](255) NULL,
[RevDATE] [datetime] NULL,
[Originator] [nvarchar](255) NULL,
[old Recipient] [nvarchar](255) NULL,
[Recipient] [nvarchar](255) NULL,
[Serial No] [nvarchar](255) NULL,
[Subject] [nvarchar](255) NULL,
[Type Code] [nvarchar](255) NULL,
[Copies] [nvarchar](255) NULL,
[Remark] [nvarchar](255) NULL,
CONSTRAINT [PK_tblTranstoCon_1] PRIMARY KEY CLUSTERED
(
[TRANSMITtoConId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

/****** Object: Table [dbo].[tblDocTranstoCon] Script Date: 06/26/2013 00:00:17 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[tblDocTranstoCon](
[DocID] [int] NOT NULL,
[TransId] [int] NOT NULL,
[TRANSMITtoConId] [int] NOT NULL,
CONSTRAINT [PK_tblDocTranstoCon] PRIMARY KEY CLUSTERED
(
[DocID] ASC,
[TransId] ASC,
[TRANSMITtoConId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[tblDocTranstoCon] WITH CHECK ADD CONSTRAINT [FK_tblDocTranstoCon_tblTransmittalls] FOREIGN KEY([DocID], [TransId])
REFERENCES [dbo].[tblTransmittalls] ([DocID], [TransId])
GO

ALTER TABLE [dbo].[tblDocTranstoCon] CHECK CONSTRAINT [FK_tblDocTranstoCon_tblTransmittalls]
GO

ALTER TABLE [dbo].[tblDocTranstoCon] WITH CHECK ADD CONSTRAINT [FK_tblDocTranstoCon_tblTranstoCon] FOREIGN KEY([TRANSMITtoConId])
REFERENCES [dbo].[tblTranstoCon] ([TRANSMITtoConId])
GO

ALTER TABLE [dbo].[tblDocTranstoCon] CHECK CONSTRAINT [FK_tblDocTranstoCon_tblTranstoCon]
GO


---------------------------------------------------------------


INSERT INTO [dbo].[tblDocuments]
([Originator]
,[Document Type]
,[Unit]
,[EQ-IN Identify/Material Code]
,[Sequential No]
,[DocumentNo]
,[TITLE])
VALUES
('Abad','dw','100','1441','001','doc-001','test1'),
('paya','dw','140','1441','005','doc-005','test2')


GO


INSERT INTO [dbo].[tbltransmittalNo]
([TRANSMITTAL]
,[RevDATE]
,[Originator Code]
,[Originator Location]
,[Recipient Code]
,[Recipient Location]
,[Serial No]
,[Subject]
,[Originator]
,[Reciever]
,[Attention])
VALUES
('tt-0002', null,null,null,null,null,null,null,null,null,null)
GO
-------------------------------------------------------------------
INSERT INTO [dbo].[tblTransmittalls]
([DocID]
,[REV]
,[TransId]
,[Pages]
,[Class]
,[Size]
,[PurposeofIssue]
,[DefaultForDocument])
VALUES
(1,'0',1,null,null,null,null,null),
(2,'0',1, null,null,null,null,null)

GO
------------------------------------------------------------

INSERT INTO [dbo].[tblTranstoCon]
([TRANSMITtoCon]
,[Oldtransmittocon]
,[RevDATE]
,[Originator]
,[old Recipient]
,[Recipient]
,[Serial No]
,[Subject]
,[Type Code]
,[Copies]
,[Remark])
VALUES
('con-0003',null,null,null,null,null,null,null,null,null,null),

('con-0005',null,null,null,null,null,null,null,null,null,null),

('con-0007',null,null,null,null,null,null,null,null,null,null)


GO
INSERT INTO [dbo].[tblDocTranstoCon]
([DocID]
,[TransId]
,[TRANSMITtoConId])
VALUES
(1,1,1),
(1,1,3),
(2,1,2)

GO



Here are the results:



(2 row(s) affected)

(1 row(s) affected)
Msg 547, Level 16, State 0, Line 2
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_tblTransmittalls_tblDocuments". The conflict occurred in database "test", table "dbo.tblDocuments", column 'DocId'.
The statement has been terminated.

(3 row(s) affected)
Msg 547, Level 16, State 0, Line 1
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_tblDocTranstoCon_tblTransmittalls". The conflict occurred in database "test", table "dbo.tblTransmittalls".
The statement has been terminated.



If I remove the foreign key constraints on all those tables like this:


CREATE TABLE [dbo].[tblDocuments](
[Originator] [nvarchar](255) NOT NULL,
[Document Type] [nvarchar](255) NOT NULL,
[Unit] [nvarchar](255) NOT NULL,
[EQ-IN Identify/Material Code] [nvarchar](255) NOT NULL,
[Sequential No] [nvarchar](50) NULL,
[DocId] [int] IDENTITY(17314,1) NOT NULL,
[DocumentNo] [nvarchar](200) NOT NULL,
[TITLE] [nvarchar](255) NOT NULL,
CONSTRAINT [PK_tblDocuments_1] PRIMARY KEY CLUSTERED
(
[DocId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

/****** Object: Table [dbo].[tbltransmittalNo] Script Date: 06/25/2013 23:56:44 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[tbltransmittalNo](
[TRANSMITTAL] [nvarchar](200) NOT NULL,
[TransID] [int] IDENTITY(8858,1) NOT NULL,
[RevDATE] [datetime] NULL,
[Originator Code] [nvarchar](50) NULL,
[Originator Location] [nvarchar](50) NULL,
[Recipient Code] [nvarchar](50) NULL,
[Recipient Location] [nvarchar](50) NULL,
[Serial No] [nvarchar](50) NULL,
[Subject] [nvarchar](50) NULL,
[Originator] [nvarchar](50) NULL,
[Reciever] [nvarchar](50) NULL,
[Attention] [nvarchar](50) NULL,
CONSTRAINT [PK_tbltransmittalNo_1] PRIMARY KEY CLUSTERED
(
[TransID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

/****** Object: Table [dbo].[tblTransmittalls] Script Date: 06/25/2013 23:57:57 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[tblTransmittalls](
[DocID] [int] NOT NULL,
[REV] [nvarchar](255) NULL,
[TransId] [int] NOT NULL,
[Pages] [nvarchar](50) NULL,
[Class] [nvarchar](50) NULL,
[Size] [nvarchar](50) NULL,
[PurposeofIssue] [nvarchar](50) NULL,
[DefaultForDocument] [bit] NULL,
CONSTRAINT [PK_tblTransmittalls_1] PRIMARY KEY CLUSTERED
(
[DocID] ASC,
[TransId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[tblTranstoCon](
[TRANSMITtoConId] [int] IDENTITY(2212,1) NOT NULL,
[TRANSMITtoCon] [nvarchar](50) NOT NULL,
[Oldtransmittocon] [nvarchar](255) NULL,
[RevDATE] [datetime] NULL,
[Originator] [nvarchar](255) NULL,
[old Recipient] [nvarchar](255) NULL,
[Recipient] [nvarchar](255) NULL,
[Serial No] [nvarchar](255) NULL,
[Subject] [nvarchar](255) NULL,
[Type Code] [nvarchar](255) NULL,
[Copies] [nvarchar](255) NULL,
[Remark] [nvarchar](255) NULL,
CONSTRAINT [PK_tblTranstoCon_1] PRIMARY KEY CLUSTERED
(
[TRANSMITtoConId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

/****** Object: Table [dbo].[tblDocTranstoCon] Script Date: 06/26/2013 00:00:17 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[tblDocTranstoCon](
[DocID] [int] NOT NULL,
[TransId] [int] NOT NULL,
[TRANSMITtoConId] [int] NOT NULL,
CONSTRAINT [PK_tblDocTranstoCon] PRIMARY KEY CLUSTERED
(
[DocID] ASC,
[TransId] ASC,
[TRANSMITtoConId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

---------------------------------------------------------------


INSERT INTO [dbo].[tblDocuments]
([Originator]
,[Document Type]
,[Unit]
,[EQ-IN Identify/Material Code]
,[Sequential No]
,[DocumentNo]
,[TITLE])
VALUES
('Abad','dw','100','1441','001','doc-001','test1'),
('paya','dw','140','1441','005','doc-005','test2')


GO


INSERT INTO [dbo].[tbltransmittalNo]
([TRANSMITTAL]
,[RevDATE]
,[Originator Code]
,[Originator Location]
,[Recipient Code]
,[Recipient Location]
,[Serial No]
,[Subject]
,[Originator]
,[Reciever]
,[Attention])
VALUES
('tt-0002', null,null,null,null,null,null,null,null,null,null)
GO
-------------------------------------------------------------------
INSERT INTO [dbo].[tblTransmittalls]
([DocID]
,[REV]
,[TransId]
,[Pages]
,[Class]
,[Size]
,[PurposeofIssue]
,[DefaultForDocument])
VALUES
(1,'0',1,null,null,null,null,null),
(2,'0',1, null,null,null,null,null)

GO
------------------------------------------------------------

INSERT INTO [dbo].[tblTranstoCon]
([TRANSMITtoCon]
,[Oldtransmittocon]
,[RevDATE]
,[Originator]
,[old Recipient]
,[Recipient]
,[Serial No]
,[Subject]
,[Type Code]
,[Copies]
,[Remark])
VALUES
('con-0003',null,null,null,null,null,null,null,null,null,null),

('con-0005',null,null,null,null,null,null,null,null,null,null),

('con-0007',null,null,null,null,null,null,null,null,null,null)


GO
INSERT INTO [dbo].[tblDocTranstoCon]
([DocID]
,[TransId]
,[TRANSMITtoConId])
VALUES
(1,1,1),
(1,1,3),
(2,1,2)

GO



Now all the objects and data are created. But your query returns an empty result set. If I change ALL of the joins to left joins it returns only 2 rows.


SELECT dbo.tblDocuments.DocumentNo, dbo.tbltransmittalNo.TRANSMITTAL, dbo.tblTranstoCon.TRANSMITtoCon
FROM dbo.tblDocuments
left JOIN dbo.tblTransmittalls ON dbo.tblDocuments.DocId = dbo.tblTransmittalls.DocID
left JOIN dbo.tbltransmittalNo ON dbo.tblTransmittalls.TransId = dbo.tbltransmittalNo.TransID
left JOIN dbo.tblDocTranstoCon ON dbo.tblTransmittalls.DocID = dbo.tblDocTranstoCon.DocID AND
dbo.tblTransmittalls.TransId = dbo.tblDocTranstoCon.TransId
left JOIN dbo.tblTranstoCon ON dbo.tblDocTranstoCon.TRANSMITtoConId = dbo.tblTranstoCon.TRANSMITtoConId



I am willing to help you but we have to have a common ground to get started. For the sake of our discussion the foreign keys can probably be left off but I have to be able to produce the same results as you.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
masoud_sedighy
masoud_sedighy
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 14
Hi

excuse me the problem of ddl was about (IDENTITY) that used previous values when we inserting data, so i change the value to (1) and now is ok when we run DDL like below, sample data also is ok now.

now my question is how i can add fields of parent and position for this query with returning parent and position value of each field.

before i have seen a sample access database that uses parent & position of each field for populating tree view.
i asked my question in many forums about how i can have parent and position value of each field/node but i did not get answer.

"http://www.access-programmers.co.uk/forums/showthread.php?t=170577"

i read some where in google we have to use union query and after adding parent & position value but there is not any sample about how we have to do?

thanks in advanced.





CREATE TABLE [dbo].[tblDocuments](
[Originator] [nvarchar](255) NOT NULL,
[Document Type] [nvarchar](255) NOT NULL,
[Unit] [nvarchar](255) NOT NULL,
[EQ-IN Identify/Material Code] [nvarchar](255) NOT NULL,
[Sequential No] [nvarchar](50) NULL,
[DocId] [int] IDENTITY(1,1) NOT NULL,
[DocumentNo] [nvarchar](200) NOT NULL,
[TITLE] [nvarchar](255) NOT NULL,
CONSTRAINT [PK_tblDocuments_1] PRIMARY KEY CLUSTERED
(
[DocId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

/****** Object: Table [dbo].[tbltransmittalNo] Script Date: 06/25/2013 23:56:44 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[tbltransmittalNo](
[TRANSMITTAL] [nvarchar](200) NOT NULL,
[TransID] [int] IDENTITY(1,1) NOT NULL,
[RevDATE] [datetime] NULL,
[Originator Code] [nvarchar](50) NULL,
[Originator Location] [nvarchar](50) NULL,
[Recipient Code] [nvarchar](50) NULL,
[Recipient Location] [nvarchar](50) NULL,
[Serial No] [nvarchar](50) NULL,
[Subject] [nvarchar](50) NULL,
[Originator] [nvarchar](50) NULL,
[Reciever] [nvarchar](50) NULL,
[Attention] [nvarchar](50) NULL,
CONSTRAINT [PK_tbltransmittalNo_1] PRIMARY KEY CLUSTERED
(
[TransID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

/****** Object: Table [dbo].[tblTransmittalls] Script Date: 06/25/2013 23:57:57 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[tblTransmittalls](
[DocID] [int] NOT NULL,
[REV] [nvarchar](255) NULL,
[TransId] [int] NOT NULL,
[Pages] [nvarchar](50) NULL,
[Class] [nvarchar](50) NULL,
[Size] [nvarchar](50) NULL,
[PurposeofIssue] [nvarchar](50) NULL,
[DefaultForDocument] [bit] NULL,
CONSTRAINT [PK_tblTransmittalls_1] PRIMARY KEY CLUSTERED
(
[DocID] ASC,
[TransId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[tblTransmittalls] WITH CHECK ADD CONSTRAINT [FK_tblTransmittalls_tblDocuments] FOREIGN KEY([DocID])
REFERENCES [dbo].[tblDocuments] ([DocId])
GO

ALTER TABLE [dbo].[tblTransmittalls] CHECK CONSTRAINT [FK_tblTransmittalls_tblDocuments]
GO

ALTER TABLE [dbo].[tblTransmittalls] WITH NOCHECK ADD CONSTRAINT [FK_tblTransmittalls_tbltransmittalNo] FOREIGN KEY([TransId])
REFERENCES [dbo].[tbltransmittalNo] ([TransID])
GO

ALTER TABLE [dbo].[tblTransmittalls] NOCHECK CONSTRAINT [FK_tblTransmittalls_tbltransmittalNo]
GO

ALTER TABLE [dbo].[tblTransmittalls] ADD CONSTRAINT [DF_tblTransmittalls_DefaultForDocument] DEFAULT ((0)) FOR [DefaultForDocument]
GO

/****** Object: Table [dbo].[tblTranstoCon] Script Date: 06/25/2013 23:59:14 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[tblTranstoCon](
[TRANSMITtoConId] [int] IDENTITY(1,1) NOT NULL,
[TRANSMITtoCon] [nvarchar](50) NOT NULL,
[Oldtransmittocon] [nvarchar](255) NULL,
[RevDATE] [datetime] NULL,
[Originator] [nvarchar](255) NULL,
[old Recipient] [nvarchar](255) NULL,
[Recipient] [nvarchar](255) NULL,
[Serial No] [nvarchar](255) NULL,
[Subject] [nvarchar](255) NULL,
[Type Code] [nvarchar](255) NULL,
[Copies] [nvarchar](255) NULL,
[Remark] [nvarchar](255) NULL,
CONSTRAINT [PK_tblTranstoCon_1] PRIMARY KEY CLUSTERED
(
[TRANSMITtoConId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

/****** Object: Table [dbo].[tblDocTranstoCon] Script Date: 06/26/2013 00:00:17 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[tblDocTranstoCon](
[DocID] [int] NOT NULL,
[TransId] [int] NOT NULL,
[TRANSMITtoConId] [int] NOT NULL,
CONSTRAINT [PK_tblDocTranstoCon] PRIMARY KEY CLUSTERED
(
[DocID] ASC,
[TransId] ASC,
[TRANSMITtoConId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[tblDocTranstoCon] WITH CHECK ADD CONSTRAINT [FK_tblDocTranstoCon_tblTransmittalls] FOREIGN KEY([DocID], [TransId])
REFERENCES [dbo].[tblTransmittalls] ([DocID], [TransId])
GO

ALTER TABLE [dbo].[tblDocTranstoCon] CHECK CONSTRAINT [FK_tblDocTranstoCon_tblTransmittalls]
GO

ALTER TABLE [dbo].[tblDocTranstoCon] WITH CHECK ADD CONSTRAINT [FK_tblDocTranstoCon_tblTranstoCon] FOREIGN KEY([TRANSMITtoConId])
REFERENCES [dbo].[tblTranstoCon] ([TRANSMITtoConId])
GO

ALTER TABLE [dbo].[tblDocTranstoCon] CHECK CONSTRAINT [FK_tblDocTranstoCon_tblTranstoCon]
GO


---------------------------------------------------------------


INSERT INTO [dbo].[tblDocuments]
([Originator]
,[Document Type]
,[Unit]
,[EQ-IN Identify/Material Code]
,[Sequential No]
,[DocumentNo]
,[TITLE])
VALUES
('Abad','dw','100','1441','001','doc-001','test1'),
('paya','dw','140','1441','005','doc-005','test2')


GO


INSERT INTO [dbo].[tbltransmittalNo]
([TRANSMITTAL]
,[RevDATE]
,[Originator Code]
,[Originator Location]
,[Recipient Code]
,[Recipient Location]
,[Serial No]
,[Subject]
,[Originator]
,[Reciever]
,[Attention])
VALUES
('tt-0002', null,null,null,null,null,null,null,null,null,null)
GO
-------------------------------------------------------------------
INSERT INTO [dbo].[tblTransmittalls]
([DocID]
,[REV]
,[TransId]
,[Pages]
,[Class]
,[Size]
,[PurposeofIssue]
,[DefaultForDocument])
VALUES
(1,'0',1,null,null,null,null,null),
(2,'0',1, null,null,null,null,null)

GO
------------------------------------------------------------

INSERT INTO [dbo].[tblTranstoCon]
([TRANSMITtoCon]
,[Oldtransmittocon]
,[RevDATE]
,[Originator]
,[old Recipient]
,[Recipient]
,[Serial No]
,[Subject]
,[Type Code]
,[Copies]
,[Remark])
VALUES
('con-0003',null,null,null,null,null,null,null,null,null,null),

('con-0005',null,null,null,null,null,null,null,null,null,null),

('con-0007',null,null,null,null,null,null,null,null,null,null)


GO
INSERT INTO [dbo].[tblDocTranstoCon]
([DocID]
,[TransId]
,[TRANSMITtoConId])
VALUES
(1,1,1),
(1,1,3),
(2,1,2)

GO








SELECT dbo.tblDocuments.DocumentNo, dbo.tbltransmittalNo.TRANSMITTAL, dbo.tblTranstoCon.TRANSMITtoCon
FROM dbo.tblDocuments
left JOIN dbo.tblTransmittalls ON dbo.tblDocuments.DocId = dbo.tblTransmittalls.DocID
left JOIN dbo.tbltransmittalNo ON dbo.tblTransmittalls.TransId = dbo.tbltransmittalNo.TransID
left JOIN dbo.tblDocTranstoCon ON dbo.tblTransmittalls.DocID = dbo.tblDocTranstoCon.DocID AND
dbo.tblTransmittalls.TransId = dbo.tblDocTranstoCon.TransId
left JOIN dbo.tblTranstoCon ON dbo.tblDocTranstoCon.TRANSMITtoConId = dbo.tblTranstoCon.TRANSMITtoConId



Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25881 Visits: 17511
Thanks again for posting your data. It all seems to be fine now. :-)

I am at a bit of a loss as to the logic here. I can't seem to quite figure out what you are looking for as output. Can you explain the business logic of what makes something a parent to something else?

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
masoud_sedighy
masoud_sedighy
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 14
as i explained before i received docno with different transmittalno and then send them by different transmittaltoCon.

docno is parent of transmittal and transmittal is parent of transmittaltocon.

for excample
today i recieve (doc-001) revesion 1 with transmittal tt-001 and send it by transmittaltoCon (con-005),(con-009)

after tomarrow i recieved (doc-001) revision 2 with transmittal tt-800 and send it by transmittaltoCon (con-1000,con-2000)

so in the treeview docno is level1 and transmittal is level2 and transmittaltoCon is level3

doc-001
|
|
------tt-001----------
| |
-----con-005
| |
----con-009
|
-------tt-800 |

|-----con-1000
|----- con-2000




now i need parent and position value of each field/node in the query
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search