简体   繁体   English

SQL Server 中的自定义查询

[英]Custom query in SQL Server

First I am using sql server, .NET and crystal report.首先我使用 sql server、.NET 和水晶报表。 I have a table called vehicles contain name, model, price and other data.我有一个名为车辆的表,其中包含名称、型号、价格和其他数据。 I want to allow the user to get a custom report by speicfy the vehicle price and the condition( > or < or = ) and get all vehicles that has the same condition.How can I do that?我想让用户通过指定车辆价格和条件(> 或 < 或 = )来获取自定义报告,并获取所有具有相同条件的车辆。我该怎么做?

在此处输入图片说明

Unfortunately I did not get any useful answer, after search I got a good method.不幸的是我没有得到任何有用的答案,经过搜索我得到了一个很好的方法。 Not the best but it is useful.不是最好的,但它很有用。 First I created a procedure in sql server as the following :首先,我在 sql server 中创建了一个过程,如下所示:

create proc get_vehicles
@condition varchar(1),
@price varchar(20)
as

declare @SQL VarChar(1000)

set @SQL = 'SELECT * FROM vehicles ' 

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

Exec ( @SQL)

go

Then I created a crystalReportViewer file and call "get_vehicles" procedure.然后我创建了一个 CrystalReportViewer 文件并调用“get_vehicles”程序。

Finally, in button "get report" I take the user choice from radioButtons and textBox and set them into crystalReportView parameters.最后,在“获取报告”按钮中,我从radioButtons 和textBox 中选择用户,并将它们设置为crystalReportView 参数。 I answered my question to help other beginners programmers like me.我回答了我的问题以帮助像我这样的其他初学者程序员。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM