substitution variables to temporarily store value

  • I am looking for "substitution variables to temporarily store value" with sqlcmd in sql server . I know the query in oracle, but can somebody tell me the equivalent query in sql server?

    In oracle query is like this:

    select *

    from tablename

    where deptnumber = &department_number;

    Enter Value for department_number

    I am looking this query in sql serevr2008.

    More appreciated,

  • select *

    from tablename

    where deptnumber = &department_number;

    Enter Value for department_number

    if you do this in SQL Server...

    SELECT *

    FROM tableName

    WHERE deptNumber = @DeptNumber

    You will get a prompt in the GUI. If you're looking at something more like a command-line thing like Oracle does, I'm not sure.

  • Just remember that SQL Server <> Oracle. JUst because there are things that can be done in Oracle doesn't mean other RDBM systems wiill provide the same functionality.

  • Hi Lynn,

    Thanks for your answer.I will explain a little more about my problem in the Myscript.sql query:

    I am using sqlcmd in command line:

    sqlcmd -U username -d dbname -i c:\mypath\myscript.sql -o c:\mypath\Myoutput.txt ( which this works )

    Myscripy.sql : ( My problem )

    declare @id_number int = 100

    select * from tablename

    where id = @id_number

    My problem is in this query, which it does not give me a situation to enter id number from outside of the query like:

    Enter Value for id_number :

    because I want to enter the value of id_number from outside of query.

    Again thank you for your attention to this matter, Marjan

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

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