Running SQL Script - Make certain text mandatory

  • I have the following code, which shows on an ASP page.

    This script is ran each time a specific database is restored.

    Often the 'Enter Name Here' part is left as such which then displays that exact text on the asp page.

    Is there any way that each time the script is manually ran, that the 'Enter Name Here' is mandatory to fill in so something has to be put in?

    Sorry, i'm not too advanced in SQL

    DECLARE @Name varchar(50)

    SET @Name = 'Enter Name Here'

    ---------------

    UPDATE [Table]

    SET [Column] = 'Name - <font color="red">'+@Name+'</font>

    Restore Date - <font color="red">' + CAST(GetDate() AS VARCHAR(11))+'</font>

    Other Text Here'

    WHERE Code = 'Code'

  • The best way is to have the ASP page call a stored procedure that requires the value.

  • I'm assuming at present this script resides somewhere on a file system as a .sql script file and is manually executed after each restore.

    You could add the following code prior to the update statement.

    IF (@Name IS NULL OR @Name = 'Enter Name Here' OR @Name = '')

    BEGIN

    PRINT 'A name must be supplied'

    RETURN

    END

    This will do some very basic validation on the @Name variable and display a message informing the user executing the script that the value hasn't been supplied. However this does not stop the code segment from being commented out, it also has no knowledge of what a valid value might be!

    To secure the script from being edited it could be placed within a stored procedure and the users given only EXECUTE permissions to it.

    Might I ask what the @Name variable should hold?

    From your post I would guess @Name is the name of the database that has just been restored, in which case you could set the value using the DB_NAME() function (e.g. SET @Name = DB_NAME()).

    MCITP SQL Server 2005/2008 DBA/DBD

  • I think this is data input validation that needs to occur on the asp page, and not at the server or even SQL server; a simple javascript alert is all you need.

    you can search for "javascript onsubmit validation" to find some examples of how to validate your asp forms with javascript;

    http://javascript.blogsome.com/2007/05/25/onsubmit-example/

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply