简体   繁体   English

SQL Server与Access SQL用户输入

[英]SQL Server vs. Access SQL User Input

Is it possible to create a user determined statistic into SSMS? 是否可以在SSMS中创建用户确定的统计信息?

For example, if I wanted to have the user input an end and start date and the query print the data from this date range, how would I do this (if possible)? 例如,如果我想让用户输入结束日期和开始日期,并且查询会打印该日期范围内的数据,我将如何执行此操作(如果可能)?

WHERE table.date BETWEEN @StartDate AND @EndDate

I've tried this, but it doesn't seem to work. 我已经尝试过了,但是似乎没有用。

My complete code is: 我完整的代码是:

SELECT [id], [state], [CitationsReceived], [date] FROM table WHERE table.date BETWEEN @StartDate AND @EndDate

My columns are id, state, CitationsReceived, date. 我的列是id,状态,CitationsReceived,日期。 I know that in Access SQL, I could type @StartDate and @EndDate without having those columns and it would create a user input which assigned the two entered dates to Start and EndDate. 我知道在Access SQL中,我可以键入@StartDate和@EndDate而不使用这些列,它将创建一个用户输入,该输入将两个输入的日期分配给Start和EndDate。 Is there any way to do this in SQL Server? 在SQL Server中有什么方法可以做到这一点?

Yes. 是。 Your syntax if fine, but you'll need to declare your parameters (@StartDate, etc) before the query. 您的语法不错,但是在查询之前需要声明参数(@StartDate等)。 For example: 例如:

DECLARE @StartDate date = '2017-05-01'

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

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