Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt issues with temporary tables, QODBC/MS SQL Server
Forum Update on Monday, May 27th 2025

Qt issues with temporary tables, QODBC/MS SQL Server

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    someguy
    wrote on 24 Oct 2011, 18:21 last edited by
    #1

    Hi folks,

    I'm having an issue doing anything with temporary tables within MS SQL Server while connected from Qt (4.7.3).

    Here is an example piece of code, assume I am already connected:

    @
    QString querystr = "SELECT * INTO #TBUL1 FROM RealTable;";
    querystr += "SELECT * FROM #TBUL1";
    model.setQuery(querystr, database);
    @

    It will tell me that the query is active and be without query or model errors, but there will be no data coming back to examine in the model (I've also tried doing it with a bare QSqlQuery object as well, and have attempted executing those statements individually).

    When I execute this code, I am watching inside MS SQL Server Management Studio and I can even see the temporary table being created 'dbo.#TBUL1___________________' inside 'tempdb' during the session, but I don't seem to be able to do anything to the table after that.

    When executing these exact statements as an isolated Query within Management Studio, I get my expected result of the 1 row currently in RealTable.

    For reference, I have had no issues querying actual tables.

    Thank you for reading, and I would appreciate any help!

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on 25 Oct 2011, 09:04 last edited by
      #2

      -You're actually having two queries here. I suggest you split them up and execute the select for the temporary table separately.-

      Sorry, I didn't read that you tried that already.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • S Offline
        S Offline
        someguy
        wrote on 25 Oct 2011, 16:45 last edited by
        #3

        Thanks for the reply. It turns out I simply didn't do it properly beforehand, but making subsequent queries is a solution to manipulate temporary tables:

        @
        QString querystr = "SELECT * INTO #TBUL1 FROM RealTable;";
        QString querystr2 = "SELECT * FROM #TBUL1;";
        model.setQuery(querystr, database);
        model.setQuery(querystr2, database);
        @

        This actually does the trick.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on 26 Oct 2011, 12:32 last edited by
          #4

          Maybe just calling the first select creating the temp table can be moved to a simple [[Doc:QSqlQuery]] call. This way you would save yourself a reset on your model.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0

          1/4

          24 Oct 2011, 18:21

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved