Search code examples
batch-filesqlcmdfindstr

Include findstr output which contains SP name in sqlcmd


How should i include the output of a findstr which retrieves me the name of the stored proc in sqlcmd?

@ECHO OFF    
FOR %%f IN ( *.sql) DO (
var xyz = echo %%f | findstr "^test*"
sqlcmd -d databaseX -S server -e -i xyz
)

where xyz will evaluate to testStoredProc1.sql, testStoredProc2.sql and so on. These stored procs have update/insert and select statement How can i capture the value of xyz and pipe it to sqlcmd?


Solution

  • @echo off
    
    
    for  %%f in (test*.sql) do (
    
      sqlcmd -d databaseX -S server -e -i %%f
    
    )
    

    NOT TESTED!

    For further information check FOR /F , SET ,DelayedExpansion