SQL - 查询中的用户输入 [英] SQL - User input in query

查看:26
本文介绍了SQL - 查询中的用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个.详细说明俱乐部在用户输入的任意两个给定日期之间放映的所有电影.例如,俱乐部成员必须能够为查询参数输入开始日期和结束日期"

I have this. "Detail all films shown by the club between any two given dates, inputted by the user. For example a club member must be able to input a start date and an end date for the parameters for the query"

现在,我将如何处理用户输入?我能想到的唯一方法是使用 php 或带有 html 表单的东西来获取值,然后将它们作为变量提交到查询中.然而,这不是所需要的.那么,这是如何完成的,以便查询要求值?或者你不能?

Now, how would I go about doing the user input? Only way I can think of would to be using php or something with a html form getting the values and then submitting them as variables in the query. However, that's not what is needed. So, how is this done so the query would ask for values? Or can't you?

我的查询到目前为止看起来是这样.

My query so far looks like so.

SELECT film.title, film.desc, show.sdate, show.fdate
FROM film
INNER JOIN show
ON film.ID=show.filmID
WHERE sdate = '&userstart' AND fdate = '&userend'

我如何处理用户输入?另外,查询是否正确?我没有办法测试,我只有设计没有实现.

How do I go about with the user input? Also, is the query correct? I have no way of testing, I only have a design not an implementation.

非常感谢

使用 Windows 系统,MS SQL Server.

Using Windows system, MS SQL Server.

推荐答案

以下是存储过程的代码:

Here's the code for a stored procedure:

CREATE PROCEDURE SomeName(@UserStart DATETIME, @UserEnd DATETIME) 
AS BEGIN

SELECT somestuff
FROM sometable
WHERE somedate BETWEEN @UserStart AND @UserEnd

END

这篇关于SQL - 查询中的用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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