Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
ALTER Procedure [dbo].[GetMoviesForDelete]
As  
Begin  
select distinct(mt.MovieID),m.MovieName+' ('+m.Language+')' as MoviesWithLanguage from Movies m inner join MovieTimings mt  
on m.MovieID=mt.MovieID and  
-- m.Status != 'Closed' and   
m.Active = 1 and mt.Active =1 and m.Active=1  
 and convert(varchar,m.ReleaseDate,112)<convert(varchar,getdate(),112)>
and m.MovieID not in (select distinct(MovieID) from MovieTimings where  
 convert(varchar,Date,112) >= convert(varchar,getdate(),112))  
End
Posted
Updated 11-Jan-13 19:30pm
v2
Comments
varun150 12-Jan-13 1:11am    
this query is not returning anything!

1 solution

Looks like you have given all your WHERE clause conditions appended to JOIN. Correct it.

You are not getting anything from table MovieTimings. You don't need a join if so. A direct query like below would do:
SQL
select
   distinct(mt.MovieID),m.MovieName+' ('+m.Language+')' as MoviesWithLanguage
from
   Movies m
WHERE
   m.Active = 1

In case you want to set something from MovieTimings table too,
Try:
SQL
ALTER Procedure [dbo].[GetMoviesForDelete]
As
Begin
select 
   distinct(mt.MovieID),m.MovieName+' ('+m.Language+')' as MoviesWithLanguage, mt.*
from 
   Movies m 
inner join 
   MovieTimings mt
   on m.MovieID=mt.MovieID and
WHERE
   m.Active = 1
 and 
   m.MovieID not in (select distinct(MovieID) from MovieTimings)
End

*Removed where clause related to date condition as it was not clear what exactly you were trying to do there and where from the field 'Date' came. You can handle it now as per your need post the simple query above.
 
Share this answer
 
Comments
varun150 12-Jan-13 4:55am    
@Sandeep Mewara
both are not working but i atleast got an error :-) with first one it says "'System.Data.DataRowView' does not contain a property with the name 'MovieName' ". although your help is apriciated.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900