I need to extract the object name from a sql text file. All of my sql files have as their 1st line "CREATE some type [schema name].[object name]. Sometimes the brackets are there, other times not. In either case, I need to be able to discern the object name affected so I can determine if it actually exists before updating the server with the new changes. I need to do this from a Windows 7 command line batch file. Not powershell, please.
Asked
Active
Viewed 268 times
-1
-
1This sounds backwards to me. You should build this type of checking into the script. – Sean Lange Feb 15 '16 at 17:07
-
2OK, you have shown us your task. Now, what is your question? Where exactly are you stuck? Surely, you don't expect us to do your job for you? – Heinzi Feb 15 '16 at 17:07
-
I really dont know where to start. I dont expect the work done for me and that remark was a little untoward. I do hope for guidance. I can open a file. I can read the file, and even likely get the 1st line of text. What I don't know how to do is get the object name out. – D J Feb 15 '16 at 17:31
-
Why not build the conditional logic into your t-sql instead of doing all these iterations outside of your script? – Sean Lange Feb 15 '16 at 17:34
-
@DJ: "How do I split a string by spaces in a batch file" is a valid SO question, whereas "Here is my task, what do I need to do it" is too broad. At the moment, your question falls into the second category, hence my comment. I'm sorry if it came over as harsh. – Heinzi Feb 15 '16 at 18:01
1 Answers
0
Doing this in a batch file is a bit like working without your hands tied behind your back, but if you insist, I would suggest the following:
Get the first line of the file (you said in the comments that you can already do this).
Voila. It won't be easy, it won't be readable, but it will do what you need and it will be a Windows cmd batch file.