Search code examples
sql-servert-sqlcrystal-reports

Crystal Reports creating temporary table with SQL Server


I'm using Crystal Reports 2008 with SQL Server 2014.

I read on the internet that it was possible to create a temporary table with Crystal Reports. This link says that, one of many examples -> Click here

Yet when I go to the database expert, create a new command and enter the following DDL

 CREATE TABLE #temp_test (col1 VARCHAR(5))

I get this error

enter image description here

Translation:

database connector error : 'No error message from server'

Yet, when I'm doing that with SQL Server on my database, everything is fine.

Have you managed to do it? If yes, how?

It sounds like an urban legend to me but I might be wrong...

Cheers


Solution

  • When you create a "Command" table in Crystal, you're giving Crystal a set of text to send to the SQL server, and Crystal expects a data set in return. Everything in between is done on the SQL server. Crystal checks the command by sending it to the SQL server when you enter it to see if it works.

    Given that, your temp table is actually created on the SQL server. Also, when you create a temp table, it is deleted after the command is finished running.

    As a result, if you use only this code, the SQL server will create the table, but there is no data set to return. It succeeds, so doesn't return an error, but also doesn't return data, hence the message: "No error message from server".

    For your next step, I would suggest using code like this:

    CREATE TABLE #temp_test (col1 VARCHAR(5))
    SELECT * FROM #temp_test
    

    This will create an empty data set to return to Crystal, so that it's getting the response it needs. I say this so that you don't think anything is wrong when you don't see anything. You'll need to insert data into the temp table in order to get it from the select statement for visual confirmation.

    I would also suggest that you don't use a temp table unless you determine that you do or will actually need one within the scope of the command. For example, you may need one to increase performance on a particularly complex query or CTE, so it might increase performance to use a temp table. But I would create that query first and worry about optimization after I have at least some of it developed.