Click here to Skip to main content
15,890,527 members
Home / Discussions / Database
   

Database

 
GeneralRe: Redundant Data? Pin
Wendelius16-Oct-08 8:43
mentorWendelius16-Oct-08 8:43 
AnswerRe: Redundant Data? Pin
jesus.online15-Oct-08 5:45
jesus.online15-Oct-08 5:45 
QuestionHow to Drop a Table with Dependencies Pin
Vimalsoft(Pty) Ltd15-Oct-08 1:39
professionalVimalsoft(Pty) Ltd15-Oct-08 1:39 
AnswerRe: How to Drop a Table with Dependencies Pin
Paddy Boyd15-Oct-08 1:56
Paddy Boyd15-Oct-08 1:56 
GeneralRe: How to Drop a Table with Dependencies Pin
Vimalsoft(Pty) Ltd15-Oct-08 20:12
professionalVimalsoft(Pty) Ltd15-Oct-08 20:12 
AnswerRe: How to Drop a Table with Dependencies Pin
Mycroft Holmes15-Oct-08 16:44
professionalMycroft Holmes15-Oct-08 16:44 
GeneralRe: How to Drop a Table with Dependencies Pin
Vimalsoft(Pty) Ltd15-Oct-08 20:13
professionalVimalsoft(Pty) Ltd15-Oct-08 20:13 
QuestionProblem with FULL OUTER JOIN Pin
dlarkin7715-Oct-08 0:42
dlarkin7715-Oct-08 0:42 
Hi,

I have two tables as follows:
CREATE TABLE [dbo].[WebSyncHistory](
	[UserID] [int] NOT NULL,
	[SyncTableName] [nvarchar](50) NOT NULL CONSTRAINT [DF_WebSyncHistory_SyncTableName]  DEFAULT (''),
	[SyncTime] [datetime] NOT NULL
) ON [PRIMARY]

CREATE TABLE [dbo].[WebSyncTimesMS](
	[UserID] [int] NOT NULL,
	[SyncTableName] [nvarchar](50) NOT NULL CONSTRAINT [DF_WebSyncTimesMS_SyncTableName]  DEFAULT (''),
	[LastActionTime] [datetime] NOT NULL
) ON [PRIMARY]

I have some records in each of these tables:
INSERT INTO WebSyncHistory VALUES (1, 'Products', '01/01/2008')
INSERT INTO WebSyncHistory VALUES (1, 'Categories', '01/01/2008')
INSERT INTO WebSyncHistory VALUES (2, 'DeviceSettings', '01/01/2008')

INSERT INTO WebSyncTimesMS VALUES (1, 'Products', '31/08/2008')
INSERT INTO WebSyncTimesMS VALUES (1, 'DeviceSettings', '01/01/2008')
INSERT INTO WebSyncTimesMS VALUES (2, 'DeviceSettings', '31/08/2008')
INSERT INTO WebSyncTimesMS VALUES (2, 'Categories', '01/01/2008')

Each table has two fields with the same name and data type
What I want to do is
select all records from each table in such a way that I end up with 4 columns - UserID, SyncTableName, SyncTime, LastActionTime
UserID	SyncTableName	SyncTime        LastActionTime
1	Products	01/01/2008	31/08/2008
1	Categories	01/01/2008	NULL
1	DeviceSettings	NULL		01/01/2008
2	DeviceSettings	01/01/2008	31/08/2008
2	Categories	NULL		01/01/2008

The closest I can get to what I want is the following:
SELECT [WebSyncHistory].[UserID]
      ,[WebSyncHistory].[SyncTableName]
      ,MAX([WebSyncHistory].[SyncTime]) As SyncTime
      ,[WebSyncTimesMS].[UserID]
      ,[WebSyncTimesMS].[SyncTableName]
      ,[WebSyncTimesMS].[LastActionTime]
FROM ([WebSyncHistory] FULL OUTER JOIN [WebSyncTimesMS] 
ON [WebSyncHistory].[UserID] = [WebSyncTimesMS].[UserID] AND [WebSyncHistory].[SyncTableName] = [WebSyncTimesMS].[SyncTableName])
	
GROUP BY [WebSyncHistory].[UserID]
      ,[WebSyncHistory].[SyncTableName]
      ,[WebSyncTimesMS].[UserID]
      ,[WebSyncTimesMS].[SyncTableName]
      ,[WebSyncTimesMS].[LastActionTime]

which returns:
UserID	SyncTableName	SyncTime			UserID	SyncTableName	LastActionTime	  
NULL	NULL		NULL				1	DeviceSettings	2008-01-01 00:00:00.000
NULL	NULL		NULL				2	Categories	2008-01-01 00:00:00.000
1	Categories	2008-01-01 00:00:00.000		NULL	NULL		NULL
1	Products	2008-01-01 00:00:00.000		1	Products	2008-08-31 00:00:00.000
2	DeviceSettings	2008-01-01 00:00:00.000		2	DeviceSettings	2008-08-31 00:00:00.000

I'm completely stumped with this one. Can anyone suggest an alternative approach?

Thanks very much,

dlarkin77
AnswerRe: Problem with FULL OUTER JOIN Pin
Syed Mehroz Alam15-Oct-08 1:43
Syed Mehroz Alam15-Oct-08 1:43 
GeneralRe: Problem with FULL OUTER JOIN Pin
dlarkin7715-Oct-08 1:51
dlarkin7715-Oct-08 1:51 
GeneralRe: Problem with FULL OUTER JOIN Pin
Syed Mehroz Alam15-Oct-08 2:07
Syed Mehroz Alam15-Oct-08 2:07 
QuestionProblem with group column Pin
eyeseetee15-Oct-08 0:01
eyeseetee15-Oct-08 0:01 
AnswerRe: Problem with group column Pin
Giorgi Dalakishvili15-Oct-08 0:10
mentorGiorgi Dalakishvili15-Oct-08 0:10 
GeneralRe: Problem with group column Pin
eyeseetee15-Oct-08 0:19
eyeseetee15-Oct-08 0:19 
GeneralRe: Problem with group column Pin
Giorgi Dalakishvili15-Oct-08 0:37
mentorGiorgi Dalakishvili15-Oct-08 0:37 
QuestionHow to change the returned data in SQL? Pin
obarahmeh14-Oct-08 23:16
obarahmeh14-Oct-08 23:16 
AnswerRe: How to change the returned data in SQL? Pin
HemJoshi14-Oct-08 23:56
HemJoshi14-Oct-08 23:56 
GeneralRe: How to change the returned data in SQL? Pin
obarahmeh15-Oct-08 2:11
obarahmeh15-Oct-08 2:11 
AnswerRe: How to change the returned data in SQL? Pin
Paddy Boyd15-Oct-08 1:57
Paddy Boyd15-Oct-08 1:57 
Questionretrieving file using SQL Query Pin
r aa j14-Oct-08 21:07
r aa j14-Oct-08 21:07 
AnswerRe: retrieving file using SQL Query Pin
Mycroft Holmes14-Oct-08 22:03
professionalMycroft Holmes14-Oct-08 22:03 
GeneralRe: retrieving file using SQL Query Pin
r aa j15-Oct-08 3:08
r aa j15-Oct-08 3:08 
Questionvisual studio 2005,SQL Data source problem Pin
amit201114-Oct-08 6:49
amit201114-Oct-08 6:49 
AnswerRe: visual studio 2005,SQL Data source problem Pin
Wendelius14-Oct-08 7:40
mentorWendelius14-Oct-08 7:40 
AnswerRe: visual studio 2005,SQL Data source problem Pin
Jerry Hammond14-Oct-08 7:48
Jerry Hammond14-Oct-08 7:48 

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.