Q:

Issue when calling dynamic procedure from sql server to .net via crystal report

I'm a beginner in sql server, so I`m appreciate to get help. I want to allow user to get vehicles data depending on price with a condition specified by user. I have this try code :
create proc get_vehicles
@condition varchar(1),
@price varchar(20)
as    

declare @SQL VarChar(1000)

set @SQL = 'SELECT * FROM vehicles  where price' 

if @condition='>'  set @sql=@sql + ' > ' + @price 
else if @condition='<'  set @sql=@sql + ' < ' + @price 
else if @condition='='  set @sql=@sql + ' = ' + @price  

Exec (@SQL)

go

This code has no problems in sql server. But when creating crystalReport file in .net and call this procedure the fields does not appear.

A:

Try it without the dynamic SQL
create proc get_vehicles
@condition varchar(1),
@price varchar(20)
as    
SELECT * 
FROM vehicles 
where (price>@price and @condition='>')
    or (price<@price and @condition='<')
    or (price=@price and @condition='=')

