简体   繁体   中英

Call SQL Query from another SQL Server Query (Management Studio)

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

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

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

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

What do you think about it?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM