I’m writing a sql script, and I’d like to use Management Studio to develop the query, and a C# program to run it in production.
My query contains parameters, like so;
SELECT * FROM TABLE
WHERE id = @id
I can feed in a value for @id in the C# program, and that works nicely. However, I also want to declare default values for testing in Management Studio. So I really want to write something like this pseudocode;
if not declared @id
declare @id int
set @id=43
end if
SELECT * FROM TABLE
WHERE id = @id
Is there any way to check to see if a variable name has already been taken?
I’ve managed to make some progress by marking out the default variables in the script, like so;
Then preprocessing the script in my C# program, like so;
And implementing the function like so;
So the C# program runs a version without the variables but with parameters.