1

I know this is redundant, but I'd like to Call Query from another Query. I know I can just add it to first one, but the scripts are getting long and at times I don't want to run all of the queries.

I've been looking and my best guess is maybe just using command shell. I was just wondering if there was another way.

Declare @CommandDos VarChar(150) = 'sqlcmd -E -S Server-i h:\SQL\SomeThing.sql'
EXEC master..xp_cmdshell @CommandDos

2 Answers 2

1

Code re-use. Perhaps use functions, i.e. put the query you want called into a function.

Functions can be Scalar, Table-valued, Deterministic, or Nondeterministic.

Sign up to request clarification or add additional context in comments.

1 Comment

Ended up just using functions and Variable temp table.
1

Maybe you can create stored procedures with the queries, then call them inside another one if needed.

What do you think about it?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.