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)
 Sql Query to get result my date

Author  Topic 

kgadde
Starting Member

5 Posts

Posted - 2008-06-14 : 13:18:24
hi
this seems to be a simple query. but i could not get it for the last 2 days. so please help.
i have 2 tables.1.lineup table 2.station table
Script for 2 tables
CREATE TABLE [dbo].[lineup](
[LineUpID] [int] IDENTITY(1,1) NOT NULL,
[headend_id] [int] NULL,
[station_num] [int] NULL,
[Channel_position] [int] NULL,
[CreateDate] [smalldatetime] NULL
) ON [PRIMARY]

CREATE TABLE [dbo].[station](
[StationId] [int] IDENTITY(1,1) NOT NULL,
[Station_num] [int] NOT NULL,
[Station_call_sign] [varchar](10) NULL,
[CreateDate] [smalldatetime] NULL
) ON [PRIMARY]

insert into lineup ("lineupid","headend_id","station_num","channel_position","createdate") values ('4182570','90973','19510','10','04/09/2008')
insert into lineup ("lineupid","headend_id","station_num","channel_position","createdate") values ('4182575','90973','10000','120','04/09/2008')
insert into lineup ("lineupid","headend_id","station_num","channel_position","createdate") values ('4182000','90000','12200','100','04/09/2008')
insert into lineup ("lineupid","headend_id","station_num","channel_position","createdate") values ('4182333','90234','12270','15','04/09/2008')
insert into lineup ("lineupid","headend_id","station_num","channel_position","createdate") values ('4182570','90973','19510','10','04/10/2008')
insert into lineup ("lineupid","headend_id","station_num","channel_position","createdate") values ('4182575','90973','10000','120','04/10/2008')
insert into lineup ("lineupid","headend_id","station_num","channel_position","createdate") values ('4182000','90000','12200','100','04/10/2008')
insert into lineup ("lineupid","headend_id","station_num","channel_position","createdate") values ('4182333','90234','12270','15','04/10/2008')
insert into station ("stationid","station_num","station_call_sign","createdate") values ('300','10000','ESPN','04/10/2008'

i want the result to be in this format
for the following columns.
i need all rows for headend_id = 90973 and createdate = 04/10/2008
please help
thanks in advance
the resultset column names should have :
headend_id channel_position station_call_sign station_num

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-14 : 14:07:46
[code]SELECT l.headend_id,
l.channel_position,
s.station_call_sign,
l.station_num
FROM lineup l
LEFT JOIN station s
ON s.station_num=i.station_num
WHERE l.headend_id = 90973
and l.createdate = 04/10/2008[/code]

If you want only those records in lineup having matching records in station change LEFT JOIN to INNER JOIN
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-06-14 : 14:09:26
And you need to use single quotes around the date values

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-14 : 14:11:38
quote:
Originally posted by madhivanan

And you need to use single quotes around the date values

Madhivanan

Failing to plan is Planning to fail


Hi Madhi. Still in hunt.
So when are you returning to India?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-06-14 : 14:33:56
quote:
Originally posted by visakh16

quote:
Originally posted by madhivanan

And you need to use single quotes around the date values

Madhivanan

Failing to plan is Planning to fail


Hi Madhi. Still in hunt.
So when are you returning to India?


Next month

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-14 : 14:42:21
quote:
Originally posted by madhivanan

quote:
Originally posted by visakh16

quote:
Originally posted by madhivanan

And you need to use single quotes around the date values

Madhivanan

Failing to plan is Planning to fail


Hi Madhi. Still in hunt.
So when are you returning to India?


Next month

Madhivanan

Failing to plan is Planning to fail


Cool
Go to Top of Page

kgadde
Starting Member

5 Posts

Posted - 2008-06-14 : 22:05:51
thanks for the reply guys.
i got what i expected
thanks
Go to Top of Page
   

- Advertisement -