+ Reply to Thread
Results 1 to 16 of 16

Split SQL Statements on Keywords

  1. #1
    Registered User
    Join Date
    03-21-2015
    Location
    GrassyKnoll
    MS-Off Ver
    2010
    Posts
    82

    Split SQL Statements on Keywords

    Hi,

    At work I have been asked to tell my manager what is different between 2 text files. The data in the text files is a bunch of SQL Statements. Most of them are super long strings. I have the comparison part down & know what is different. I have to now build a report to outline the differences. They said they would accept it in Word or Excel. I am opting for xl.

    The part I need help with is some VBA logic to break the SQL Statement into smaller bite size chunks. I was thinking of trying to use VBA's Split function to split the SQL Statements on SQL Keywords.

    Maybe there is a program that already does this. Like a feature in Sublime Text or something. If there is please mention it.

    If you know of a post where someone has already worked something like this out please point me in the right direction. I can’t be the 1st or only person who has had to do this.

    TIA

  2. #2
    Registered User
    Join Date
    03-21-2015
    Location
    GrassyKnoll
    MS-Off Ver
    2010
    Posts
    82

    Re: Split SQL Statements on Keywords

    I don’t know if SPLIT is the right approach. I see now that SPLIT wants to replace the delimiter I am using with a LineBreak. If that’s the case I might as well use REPLACE. Right? Seems to make sense. Let me see what I can cook-up with that.

    I tried posting my code but I am getting a SQL injection message. Weird I'm not doing anything malicious.

  3. #3
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Split SQL Statements on Keywords

    Can't you just use a text comparison tool and output the differences? WinDiff, git or similar?

  4. #4
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Split SQL Statements on Keywords

    Does Word's Compare not suffice? If it does, we could probably help automate it for you. Manually doing it seems simple enough though.

    https://support.office.com/en-us/art...ad=US&fromAR=1

  5. #5
    Registered User
    Join Date
    03-21-2015
    Location
    GrassyKnoll
    MS-Off Ver
    2010
    Posts
    82

    Re: Split SQL Statements on Keywords

    Yeah, I could if I knew about them. Thanks for telling me @Kyle. I will test them & see if they provide the solution.

    lol I was just thinking about it & to test it I need to put in a request with IT. Wait for it to be approved & then wait for them to install it for me. That could take 3-72 hours. lol... yeah

    I will put in the request, but I can't bank on IT getting anything installed on my machine before tomorrow morning when I have my meeting.

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Split SQL Statements on Keywords


  7. #7
    Registered User
    Join Date
    03-21-2015
    Location
    GrassyKnoll
    MS-Off Ver
    2010
    Posts
    82

    Re: Split SQL Statements on Keywords

    Hi Ken,

    I am not having a problem with comparing the files. Truly my problem is following the SQL Queries. They are so..... long [Some of these statements go from Col A - DD]. I want to BREAK them ON SQL Keywords. It would look something like below if the Forum Server lets me post it. [Fingers crossed]

    Nope it wont let me post it. [SAD face]

  8. #8
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Split SQL Statements on Keywords

    Haha I bet they're not half as long as some of the SQL I've written, I've produced some monsters in my time that I hope I never have to go back to change!

    Try the links I posted above, the sql formatter will make them look consistent and make for easier comparison, then the diff tool will tell you what's different

  9. #9
    Registered User
    Join Date
    03-21-2015
    Location
    GrassyKnoll
    MS-Off Ver
    2010
    Posts
    82

    Re: Split SQL Statements on Keywords

    Here is a before & after of the results I am trying to achieve.
    Before
    B4.PNG
    After
    After.PNG

  10. #10
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Split SQL Statements on Keywords

    The second link I posted does that, though you may have to uncomment

  11. #11
    Registered User
    Join Date
    03-21-2015
    Location
    GrassyKnoll
    MS-Off Ver
    2010
    Posts
    82

    Re: Split SQL Statements on Keywords

    lol @Kyle. Yeah you know what I am talking about. Thanks again for the insights I am going to get on making those requests. While I wait I will test on my own Rig with some sample code. Worst case I will just have to tell them I am waiting on IT. lol Hurry-up & wait.

    I think I am starting to get my head wrapped around what I was needing to do.
    Count the total words (For a ceiling for my loop)
    Find my Keywords (Counter for my CaseStatement in a For loop)
    Finally Loop through my CaseStatement & make the modification’s via REPLACE to the SQL Query & Flag each Keyword as it is done, so hopefully I don’t have any problems.

  12. #12
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Split SQL Statements on Keywords

    I think what you're trying to do makes no sense, there are tools that are on the web that don't need downloading that do what you want.

    But hey, if you like making work for yourself

  13. #13
    Registered User
    Join Date
    03-21-2015
    Location
    GrassyKnoll
    MS-Off Ver
    2010
    Posts
    82

    Re: Split SQL Statements on Keywords

    GREAT!!! @Kyle THANKS A TON.

    I guess I dont have to do all that mess after all. lol....

  14. #14
    Registered User
    Join Date
    03-21-2015
    Location
    GrassyKnoll
    MS-Off Ver
    2010
    Posts
    82

    Re: Split SQL Statements on Keywords

    But hey, if you like making work for yourself
    If I didnt do that what would I do all day? lol.....
    Last edited by xlBunny; 07-27-2016 at 01:45 PM.

  15. #15
    Registered User
    Join Date
    03-21-2015
    Location
    GrassyKnoll
    MS-Off Ver
    2010
    Posts
    82

    Re: Split SQL Statements on Keywords

    Yup Im testing that link now. IT WORKS!!!! Thanks @Kyle

  16. #16
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Split SQL Statements on Keywords

    Glad it helped

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 03-23-2016, 03:28 PM
  2. Replies: 2
    Last Post: 03-08-2015, 09:31 AM
  3. Split cell to create sorted heading on empty row above and keep second split info
    By CastingDirector in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-09-2015, 12:24 AM
  4. [SOLVED] VBA looking for multiple keywords and return concatenated keywords, that were found
    By Kpacu007 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-10-2014, 06:03 AM
  5. [SOLVED] Search for keywords and copy rows containing keywords to new sheet
    By lenorsk in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-15-2013, 06:54 AM
  6. [SOLVED] HDI - Return multiple keywords in a text column based on a set of available keywords
    By zneiley in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-25-2013, 01:32 PM
  7. [SOLVED] Excel 2007 : Combine several IFs statements/keywords in a single cell
    By nazsha07 in forum Excel General
    Replies: 5
    Last Post: 06-20-2012, 09:43 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1