SQL - User input in query

前端 未结 3 1721
面向向阳花
面向向阳花 2021-01-06 00:13

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

相关标签:
3条回答
  • 2021-01-06 00:18

    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
    
    0 讨论(0)
  • 2021-01-06 00:33

    @Kyle93 - Looking at your WHERE Clause:

    WHERE sdate = '&userstart' AND fdate = '&userend'

    This will only get you Films that had a sdate(Start Date?) equal to the date value entered. You might want to use Greater than, Less Than operators....

    Such as:

    WHERE sdate <= '&userend' AND fdate >= '&userstart'

    (Note comparing sdate to UserEnd Date to make sure Film Showing started EARLIER than the UserEnd Date...etc)

    This way - when a show starts OR ends within the date range - it will be selected.

    0 讨论(0)
  • 2021-01-06 00:42

    Are you familiar at all with LINQ? It's a way to make db calls from c#.

    -- I would handle this with HTML as you thought, and use Javascript/Ajax to reference c# code that uses LINQ for db calls. Might be a bit complicated however, if you're not familiar with much of that. I can recommend good tutorials if interested tho.

    0 讨论(0)
提交回复
热议问题