Click here to Skip to main content
16,005,339 members
Home / Discussions / Database
   

Database

 
AnswerRe: Login help? Pin
Colin Angus Mackay18-May-06 20:21
Colin Angus Mackay18-May-06 20:21 
AnswerRe: Login help? Pin
eric_tran19-May-06 3:06
eric_tran19-May-06 3:06 
QuestionVB6 and MySQL without DCOM Pin
sparks8018-May-06 14:46
sparks8018-May-06 14:46 
QuestionMeasuring query execution time Pin
tibiz18-May-06 4:12
tibiz18-May-06 4:12 
QuestionCreate Complex Trigers need help Pin
dadax_8518-May-06 3:00
dadax_8518-May-06 3:00 
AnswerRe: Create Complex Trigers need help Pin
Eric Dahlvang18-May-06 6:51
Eric Dahlvang18-May-06 6:51 
GeneralRe: Create Complex Trigers need help Pin
dadax_8518-May-06 9:03
dadax_8518-May-06 9:03 
QuestionHierarchal sql query problem Pin
Paddy Boyd18-May-06 1:18
Paddy Boyd18-May-06 1:18 
OK, I think this must be possible, but my head is melting and running out my ears, any help appreciated. I have table structure like this:

Table: Statement
Columns: ID (PK)
Name
TypeCode
PeriodId

Table: Heading
Columns: ID (PK)
StatementID
Name

Table: Line
Columns: ID (PK)
HeaderId
Name

These three tables make up a hierarchal 'tree' of data for a statment (structure simplified for this example). Each statement has a period represented by an id, and there will be a number of statement types for each period. What i need to do is copy each statement for a period and all of it's children to a new period.

After creating the new statements in STATEMENT table (simple), I've been able to do this:

INSERT INTO Heading (STATEMENTID, NAME)
  SELECT SNEW.ID,H.NAME
  FROM HEADING H
  INNER JOIN STATEMENT S
  ON H.StatementID = S.ID
  LEFT OUTER JOIN STATEMENT SNEW
  ON S.TYPECODE = SNEW.TYPECODE
  AND SNEW.PeriodID = @NewID
  WHERE S.PeriodID = @PrevId


Which inserts all the heading children appropriately. I can't seem to get the join syntax correct though to go down and do the same for the lines, closest i've got is this:


SELECT HNew.ID,L.NAME,
FROM LINE L
INNER JOIN HEADING H
ON L.HEADINGID = H.ID
INNER JOIN STATEMENT S
ON H.StatementID = s.ID
LEFT OUTER JOIN STATEMENT SNEW
ON S.TYPECODE = SNEW.TYPECODE AND SNEW.PeriodID = @NewId
LEFT OUTER JOIN HEADING HNew
ON HNew.StatementID = SNEW.ID
WHERE F.PeriodId = @OldId


This returns too many records. I know my join has gone wrong somewhere, but i can't see it... Confused | :confused:

any help would be appreciated.
QuestionRe: Hierarchal sql query problem Pin
Eric Dahlvang18-May-06 6:33
Eric Dahlvang18-May-06 6:33 
AnswerRe: Hierarchal sql query problem Pin
Paddy Boyd18-May-06 22:09
Paddy Boyd18-May-06 22:09 
Questionsql/inner join statement Pin
playout18-May-06 0:44
playout18-May-06 0:44 
GeneralRe: sql/inner join statement Pin
George L. Jackson18-May-06 16:09
George L. Jackson18-May-06 16:09 
QuestionSQL Server Not Connecting Pin
Brendan Vogt18-May-06 0:32
Brendan Vogt18-May-06 0:32 
AnswerRe: SQL Server Not Connecting Pin
r.stropek4-Jun-06 5:59
r.stropek4-Jun-06 5:59 
QuestionMAXIMUM Leength of varchar Pin
NICE TO MEET18-May-06 0:28
NICE TO MEET18-May-06 0:28 
AnswerRe: MAXIMUM Leength of varchar Pin
Colin Angus Mackay18-May-06 0:35
Colin Angus Mackay18-May-06 0:35 
QuestionCombobox Pin
ADY00717-May-06 22:52
ADY00717-May-06 22:52 
QuestionComparison of two tables to catch mismatch in data Pin
Vishucool17-May-06 20:47
Vishucool17-May-06 20:47 
AnswerRe: Comparison of two tables to catch mismatch in data Pin
Jim Conigliaro19-May-06 2:11
Jim Conigliaro19-May-06 2:11 
QuestionError Message Pin
NICE TO MEET17-May-06 20:34
NICE TO MEET17-May-06 20:34 
QuestionSQL Server 7.0 Database (Suspect)? Pin
Rashar17-May-06 8:32
Rashar17-May-06 8:32 
QuestionTime interveal question Pin
NaNg1524117-May-06 7:53
NaNg1524117-May-06 7:53 
AnswerRe: Time interveal question Pin
Eric Dahlvang17-May-06 8:45
Eric Dahlvang17-May-06 8:45 
GeneralRe: Time interveal question Pin
NaNg1524117-May-06 9:11
NaNg1524117-May-06 9:11 
GeneralRe: Time interveal question Pin
Eric Dahlvang17-May-06 9:17
Eric Dahlvang17-May-06 9:17 

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.