Results 1 to 2 of 2

Thread: SQLCMD: call SP add param as contents of a file

  1. #1

    Thread Starter
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    SQLCMD: call SP add param as contents of a file

    Hi,

    I'd like to use SQLCMD to update my database. I've created a SP and am now trying to figure out how to supply one of the parameters as a variable/contents of a file, is this possible?

    I'm using SQL Server '05

    Code:
    sqlcmd -S server -U uname -P pwd /d mydb -h-1 -s"" -W /Q "exec up_gNewEmail 'This is my subject', 'This is my email body'" -o out.log
    Any help will be greatly appreciated.

    Cheers Al
    Last edited by aconybeare; Jul 22nd, 2010 at 06:48 AM. Reason: Misspelt the command (slap)

  2. #2

    Thread Starter
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    Re: SQLCMD: call SP add param as contents of a file

    Think I've got it, however it's not going to work for me because newlines are replaced with slashes "/". I can't be sure that if I replace the slashes in my SP with newlines that I won't removing legitamate slashes.

    Code:
    @echo off
    setlocal enabledelayedexpansion
    set SEPARATOR=/
    set filecontent=
    for /f "delims=" %%a in (myBody.txt) do (
      set currentline=%%a
      set filecontent=!filecontent!%SEPARATOR%!currentline!
    )
    echo The file contents are: %filecontent%
    
    sqlcmd -S server -U uname -P pwd /d mydb -h-1 -s"" -W /Q "exec up_gNewEmail 'This is my subject','%filecontent%'" -o out.log
    I'm now considering executing this thing using vbscript ".vbs"

    e.g. cscript updateMyDbAndSendMyEmail.vbs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width