Also, another question:I have two variables at the start of the script:DECLARE @sqlstmt varchar(500)DECLARE @filepath varchar(100)
if I run the script and it fails somwhere, then next time I run the script I get :Msg 134, Level 15, State 1, Line 240The variable name '@sqlstmt' has already been declared. Variable names must be unique within a query batch or stored procedure.Msg 134, Level 15, State 1, Line 241The variable name '@filepath' has already been declared. Variable names must be unique within a query batch or stored procedure.
but if I comment out the variables for the second attempt, it complains that they havn't been declared!am I missing something very obvious here? how can I make variables and temporary tables exist only for the duration of the running of the script? I realise that using SQL server management studio to execute scripts like this is similar to SQL*Plus for oracle and for these requirements I'd normally in Oracle I'd write an annonymous block (a sort of on-the-fly stored procedure) is there an equivalent I can do in SQL server to encapsulate a set of transactions and all bits and pieces related to them in one block of stand-alone logic?