如何使用存储过程按照所选下拉列表过滤数据? [英] How do I filter data as per the selected drop down using stored procedure?

查看:106
本文介绍了如何使用存储过程按照所选下拉列表过滤数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有数据库表:客户,自定义交易和交易。

我想创建一个包含客户名称的下拉列表,然后在选择特定客户时我想查看购买详细信息他们在过去31天内购买的客户。我已经完成了查询部分,但我很难搞清楚如何执行此操作。

我想在datagridview中显示它但不使用sqldatasource并使用visual studio GUI来完成所有操作。我想尝试使用存储过程。



我尝试了什么:



I have database tables : customer, customertranscations and transactions.
I want to create a dropdown list with the customer name and then on selection of a specific customer i want to view the purchase details of the customer that they have purchased within the last 31 days. I have completed the query part but i am having hard time figuring out how to do this.
I want to display it in datagridview but not use sqldatasource and use the visual studio GUI to do it all. I want to try using stored procedure.

What I have tried:

SELECT c.customer_id, c.name, t.transactions_date, t.payment_amount 
from customer c INNER JOIN customertranscations ct ON c.customer_id = ct.customer_id 
INNER JOIN transactions t on ct.transactions_id= t.transactions_id WHERE 
t.transactions_date >=DATEADD(DAY, -2, getdate() - 31 ) AND c.customer_id = 'cus1' 

推荐答案

创建存储过程可以在您需要的级别上从创建存储过程Microsoft Docs [ ^ ]





基本格式为:

Creating a stored procedure can be, at the level you need it, learned rather quickly from Create a Stored Procedure | Microsoft Docs[^]


The basic format is:
CREATE PROCEDURE SP_NAME_YOU_LIKE (
  @Declare_Input datatype, 
  @moreInput     datatype,
  etc.
)
AS
--  Your SQL Query of any sort.  Use the @values for controlling filters, 
such as
SELECT * FROM Some_Table WHERE colVal=@Declare_Input


这篇关于如何使用存储过程按照所选下拉列表过滤数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆