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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Get line colors that joins

Author  Topic 

baburk
Posting Yak Master

108 Posts

Posted - 2008-12-16 : 23:56:02
Hi,

This is my table structure.

CREATE TABLE [dbo].[Line] (
[LineID] int IDENTITY(1, 1) NOT NULL,
[Line] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Line1] varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Line2] varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Line3] varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Line4] varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Sequence1] int NULL,
[Sequence2] int NULL,
[Sequence3] int NULL,
[Sequence4] int NULL,
PRIMARY KEY CLUSTERED ([CityID]),
UNIQUE ([City])
)
ON [PRIMARY]
GO

Sample Data
INSERT INTO Line

SELECT Q, RED, NULL, NULL, 1, NULL, NULL UNION ALL
SELECT A, RED, NULL, NULL, 3, NULL, NULL UNION ALL
SELECT C, RED, GREEN, NULL, 2, 1, NULL UNION ALL
SELECT D, RED, NULL, NULL, 4, NULL, NULL UNION ALL
SELECT E, NULL, GREEN, BLUE, NULL, 1, 1 UNION ALL
SELECT F, NULL, GREEN, NULL, NULL, 3, NULL UNION ALL
SELECT G, NULL, NULL, BLUE, NULL, NULL, 2 UNION ALL
SELECT H, NULL, NULL, BLUE, NULL, NULL, 3 UNION ALL
SELECT J, NULL, NULL, BLUE, NULL, NULL, 4 UNION ALL
SELECT K, NULL, NULL, BLUE, NULL, NULL, 5

O/P

Line Join
Q 0
C 1
E 1
G 0
H 0
J 0
K 0

Sequence should be increamented by 1 or decreamented by 1

Here FromLine = Q, ToLine = K

I want to kwnow where the Color Joins. 0 = No color join, 1 = color joins.

Thanks.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-17 : 00:14:14
why have you not included D even though there's a color join happening there?
Go to Top of Page

baburk
Posting Yak Master

108 Posts

Posted - 2008-12-17 : 00:57:25
quote:
Originally posted by visakh16

why have you not included D even though there's a color join happening there?



A, D didn't come since sequence for A, D is 3, 4 and Green met C at sequence 2.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-17 : 01:05:35
seems like what you need is recursive cte
Go to Top of Page

baburk
Posting Yak Master

108 Posts

Posted - 2008-12-17 : 01:20:51
quote:
Originally posted by visakh16

seems like what you need is recursive cte



Yes

How can I able to do that.
Go to Top of Page
   

- Advertisement -