Dialogbox to input parameter in sql server like access

  • Hello comunity

    I create a simple select statment whith a variable, for example:

    declare @numcli int

    set @numcli = 11

    select name,adress from customers where customers.no = @numcli

    In ACCESS, when i define a parameter and i execute my query, before the execution a dialogbox open to put on them the value that i wish for my variable.

    The same thing is possible in SQL Server, because i don´t find anything about that, so the use of variable in SQL like my example is not dynamic .

    Many thanks

    Luis Santos

  • You can't do what you want to do on just a "plain" query stored in a file or keyed in, but...

    You can (and should) create a stored procedure to contain your query; list your variables as arguments to the stored proc.

    Then, in the SSMS Object Explorer, right-click on the query and select 'Execute Stored Procedure'. It will give you a parameter entry dialog, somewhat similar to what you're looking for.

    Rob Schripsema
    Propack, Inc.

  • Under 99% of circumstances, you'd run the procedure via a query window.

    Example, if you made this proc:

    CREATE PROC AlphaProc

    (@blah INT = NULL)

    AS

    SELECT @blah

    You would run it for different variables like so:

    EXEC AlphaProc @blah = 4

    EXEC AlphaProc @blah = 10

    EXEC AlphaProc @blah = 312552

    T-SQL is not as GUI based.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

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

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