3

I Think That My Question Is Simple. How Can I Find That My Query Is Running From Where ( Where is The Location of the Script File itself ) ?

Edit :

Thank You For Your Answer. I Need To Import a XML File Using my TSQL Script File And i want to Keep Them Together, so Wherever Someone try to run the TSQL script file, it must knows the current directory of itself to know where is the XML file and then import it. Thank Again !

5
  • It's not simple. All SQL Server knows is that it's been handed a batch of text to compile and execute. That text may have been dynamically generated by some code, or may be in an unsaved query window in SSMS, or ... (you hopefully get the idea) Commented Oct 3, 2012 at 6:34
  • 1
    This also sounds like a small part of a larger (broken) solution - perhaps if you present the overall problem that you're trying to solve, we could produce a solution that doesn't require this information. Commented Oct 3, 2012 at 6:38
  • 1
    thank for your answer, but this is weird !, why just this sample thing must be so difficult ? , Commented Oct 3, 2012 at 7:01
  • 3
    How do you expect import with TSQL, if your "script" and xml reside on client PC, but server is located on the other side of world? TSQL can't access your local PC anyway. Commented Oct 3, 2012 at 7:06
  • you're right man, my mistake :). Commented Oct 3, 2012 at 7:32

2 Answers 2

1

You need a well known location where you can place XML files for the server to load. This could be a share on the SQL Server machine, or on a file server which the SQL Server service account has permissions to read from.

You then need a comment like this at the top of your script:

--Make sure you've placed the accompanying XML file on \\RemoteMachine\UploadShare
--Otherwise, expect this script to produce errors

Change \\RemoteMachine\UploadShare to match the well known location you've selected. Optionally, have the comment followed by 30-40 blank lines (or more comments), so that it's obvious to anyone running it that they might need to read what's there.

Then, write the rest of your script based on that presumption.

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

Comments

1

I Found A Solution to my problem that's simpler ! You Know I Just Import My XML File To A Temp Table for once. Then I Write a Select Query for That Temp Table That Contains my imported Data Like This :

" SELECT 'INSERT INTO MyTable VALUES (' + Col1 + ', ' + Col2 + ')' FROM MyImportedTable "

And Now I Have Many Insert Commands For Each One Of My Imported Records. And I Save All of the Insert Commands in My Script. And So I Just Need My Script File Everywhere I Go.

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.