Groups | Blog | Home
all groups > sql server programming > november 2004 >

sql server programming : Combine 2 tables into single resultset


Dan Guzman
11/2/2004 10:48:10 PM
You can use UNION ALL to concatenate results:

SELECT
SchedStart AS Start,
SchedStop AS Stop,
SchedName AS Name
FROM tblAppointment
WHERE SchedStart ='20050101 12:00:00'
UNION ALL
SELECT
AppStart,
AppStop,
AppName
FROM tblAppointment
WHERE AppStart='20050101 12:00:00'
GO

--
Hope this helps.

Dan Guzman
SQL Server MVP

[quoted text, click to view]

Mike Hoff
11/2/2004 10:49:14 PM
Hello,

I need to get a single recordset combining 2 similar tables.

Table 1: tblAppointment
fields: AppStart (datetime), AppStop (datetime), AppName (varchar)

Table 2: tblSchedule
fields SchedStart (datetime), SchedStop (datetime), SchedName (varchar)

I would like to get a single recordset:

SELECT [SchedStart or AppStart as Start], [SchedStop or AppStop as Stop],
[SchedName or AppName as Name]
WHERE [SchedStart or AppStart='1/1/2005 12:00 pm']

Is this possible or do I need to combine them inside my app?

Thanks in advance.

Mike Hoff
11/3/2004 1:00:27 AM
Once again - works perfectly. Thanks again Dan, and Jonathan.

[quoted text, click to view]

Jonathan Chong
11/3/2004 12:51:42 PM
You can try using UNION operator:

SELECT SchedStart as Start, SchedStop as Stop,
SchedName as [Name] FROM tblSchedule
WHERE SchedStart='1/1/2005 12:00 pm'
UNION
SELECT AppStart as Start, AppStop as Stop,
AppName as [Name] FROM tblAppointment
WHERE AppStart='1/1/2005 12:00 pm'

[quoted text, click to view]

AddThis Social Bookmark Button