【问题标题】:Issue when calling dynamic procedure from sql server to .net via crystal report通过水晶报表从 sql server 调用动态过程到 .net 时出现问题
【发布时间】:2017-01-30 14:53:29
【问题描述】:

我是 sql server 的初学者,因此很高兴获得帮助。我想允许用户在用户指定的条件下根据价格获取车辆数据。我有这个尝试代码:

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

这段代码在sql server中没有问题。但是在 .net 中创建 CrystalReport 文件并调用此过程时,字段不会出现。

【问题讨论】:

    标签: .net sql-server stored-procedures crystal-reports


    【解决方案1】:

    不使用动态 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='=')
    

    【讨论】:

      猜你喜欢
      • 2013-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-31
      • 1970-01-01
      • 2010-09-22
      相关资源
      最近更新 更多