user3854793
user3854793

Reputation: 29

stored procedure gives incorrect output

I want the flimname 'gladiator' not the other film name in the output

alter proc spfilmcriteria(@Minlength as int,@maxlength as int,@title as varchar)
as
begin
select filmname,filmreleasedate,filmruntimeminutes
from tblFilm
where filmruntimeminutes > @Minlength and filmruntimeminutes< @maxlength and FilmName like  '%' + @title + '%'
order by filmruntimeminutes asc
end

exec spfilmcriteria 150,160,'gladiator'

Output:

filmname    filmreleasedate                              filmruntimeminutes
Gladiator   2000-05-12 00:00:00.000                           155
Harry Potter and the Goblet of Fire 2005-11-18 00:00:00.000   157
American Gangster   2007-11-16 00:00:00.000                   157

Upvotes: 0

Views: 38

Answers (3)

user3854793
user3854793

Reputation: 29

alter proc spfilmcriteria(@Minlength as int,@maxlength as int, @title as varchar(max))
as
begin
select filmname,filmruntimeminutes
from tblFilm
where filmruntimeminutes >= @Minlength and filmruntimeminutes<= @maxlength and FilmName like  '%' + @title + '%'
order by filmruntimeminutes asc
end

Upvotes: 0

Ubaid Ashraf
Ubaid Ashraf

Reputation: 875

@title as varchar     

It should be @title as varchar(max) or any length you storing in database

Upvotes: 1

Giorgi Nakeuri
Giorgi Nakeuri

Reputation: 35780

You have error:

alter proc spfilmcriteria(@Minlength as int,@maxlength as int,@title as varchar)

This @title as varchar defaults as @title as varchar(1)

So actuaally you are searching not gladiator, but g.

Upvotes: 2

Related Questions