Crystal Reports creating temporary table with SQL Server - 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
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

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.

Related

Access Database - Understand Pass Through

I have been given an Access Database that I have to try to decipher what it is doing.
As a start I see that there is a Pass Through query with a command like:
Exec RefreshGLTableLatestEntries
#sourceDB = 'DB_NAME' ,
#tablePrefix = 'TableName$' ,
#logFile = 'C:\logDB.txt'
When I run it I will get something like:
Result
Success... 108 rows inserted with a total amount of $0.000000
What I don't understand is where are the rows being copied from or copied to.
In the MSSQL database I don't see a table, query, standard procedure or function called 'TableName$'. There are quite a few tables & queries called 'TableName$SomethingElse'. Is there a way to see more details on where is the data coming from?
Similarly, how can I see where are the rows being inserted to? I can not find any file named 'logDB.txt' in my hard disk to see the log. I would suspect that it might not say much more that '...108 rows insterted...'
I'm using:
Access 2016 from Office 365, Version 1609
MS SQL Server Management Studio v17.1
Any ideas on how to get more information on how to get more information on what the Pass Through do?
A Pass-Through query in Access is equivalent to running its SQL code in SQL Server Management Studio.
(In the database that is designated by the connection string of the Pass-Through query.)
The SQL is sent as-is to MSSQL and run there.
RefreshGLTableLatestEntries is the stored procedure that is executed here. You need to locate and analyze it in SQL Server.

SQL Server addressing a table different than requested then firing "object name xxx invalid"

From the Object Explorer of SQL Server Management Studio I renamed a table from nameA to nameB. When I query SELECT * from nameB I receive the error
object name 'nameA' not valid
This happens both from Management Studio and an external application. SELECT * from nameA gives the same error.
Restarting the service didn't help. Table name in sysobjects is correct. Is there maybe another place where SQL Server looks up table names? Thanks, it's getting me quite crazy :S
I'm using SQL Server 11.0.2100.60
Solved with a workaround:
I generated scripts for table schema and data, dropped the table and run scripts to recreate table schema and data. NOTE: I needed to manually modify the generated scripts because of mistakes in smalldatetime fields which made the generated INSERTs fail.
So it seems that dropping tables resets the "denormalized" SQL Server internal catalog which was left inconsistent somewhen. Thanks MS! ;)

SQL Server cross database alias

I'm trying to understand how I can use an alias to reference another database in the same instance, without having to use a hardcoded name.
The scenario is as below:
I have a data db with stores data, an audit db which keeps all changes made. for various reason, i want to keep the audit data in a separate database, not least because it can get quite large and for reporting purposes.
In the data db, I don't want to reference this by a hardcoded name but an alias so that in different environments, I don't have to change the name and various sp's to reference the new name.
for example:
mydevdata
mydevaudit
If a sp exists in mydevdata such as which calls the mydevaudit, I don't want to change the sp when I go to test where the db's may be called mytestdata and mytestaudit. Again, for various reasons, the database names can change, more to do with spaces an instances etc.
So if I had procedure in mydevdata:
proc A
begin
insert into mydevaudit.table.abc(somecol)
select 1
end
when I go to test, I don't want to be change the procedure to reference another name, (assume for sake of argument that happened)
Instead I am looking to do something like:
proc A
begin
insert into AUDITEBALIAS.table.abc(somecol)
select 1
end
I am interested in finding out how I could do something like that, and the pro's and cons.
Also, dymnamic SQL is not an option.
thanks in advance for you help.
You may be able to use synonyms
CREATE SYNONYM WholeTableAliasWithDBetc FOR TheDB.dbo.TheTable
This means all object references in the local DB are local to that DB, except for synonyms that hide the other database from you.
You can also use stored procedures in the audit DB. There is a 3rd form of EXEC that is little used where you can parametrise the stored proc name
DECLARE #module_name_var varchar(100)
SET #module_name_var = 'mydevaudit.dbo.AuditProc'
-- SET #module_name_var = 'whatever.dbo.AuditProc'
EXEC #module_name_var #p1, #p2, ...
Obviously you can change module_name_var to use whatever DB you like
I've just posted this to How to create Sql Synonym or "Alias" for Database Name? which is a workaround for the same situation:
There is a way to simulate this using a linked server. This assumes you have two SQL servers with the same set of databases one for development/test and one live.
Open SQL Server Management Studio on your development/test server
Right click Server Objects > Linked Servers
Select New Linked Server...
Select the General page
Specify alias name in Linked server field - this would normally be the name of your live server
Select SQL Native Client as the provider
Enter sql_server for Product Name
In Data Source specify the name of the development server
Add Security and Server Options to taste
Click OK
The above is for SQL Server 2005 but should be similar for 2008
Once you've done that you can write SQL like this:
SELECT * FROM liveservername.databasename.dbo.tablename
Now when your scripts are run on the development server with the linked server back to itself they will work correctly pulling data from the development server and when the exact same scripts are run on the live server they will work normally.

Crystal Reports and stored procedures with parameters

I work with Crystal Report 2008 sp2, and during creation of a new report template I've encountered a problem. I created a stored procedure, which prepares and pivots needed data on the server side, and filters it using a parameter.
When I try to add this stored procedure to the report template in Crystal Editor, I receive SQL error 102 - incorrect syntax near ')'. Although I can easily add user defined function to my report with exactly the same parameter.
What could be the source of the problem?
P.S. Stored procedure does run and return correct data if I run it in the SSMS.
As long as you are returning a record set from the store procedure try using a command object
in the command object:
EXEC mystoredProc ({?variable1}, {?variable2})
The "exec mystoredProc()" was a good try, but didn't work for me.
Crystal to/from Oracle 10g SPs is kicking MY butt... I've worked every example from BOXI/SAP, a couple from the web, and from "Crystal Reports 9 on Oracle", and all I get are Crystal's/Oracle's error messages.
The latest is "Object Specified is incompatible with the flag specified." ORA-04047, with an ORA-20004 and an Ora-06512 thrown in for good measure.
I'm trying to get the simplest SP return for a beginning... Just give me the Select * results from a table.
Any hints?
I've tried the Oracle native (client) drivers, The Oracle ODBC drivers... I haven't gotten the Crystal Oracle drivers to work, tho'.
Depending upon the driver I'm using, I can get PLS-00302 - Component must be declared.
I've written and re-written these things over and over. Right now, I'm not a happy Oracle camper. MS SQL was sooo much easier.

weird error using SQL-Server2005 SPROCs from MS Access 2000: ";1" in name --> not found

I have a weird problem here.
In short to the environment we have:
There is a (newly set up) Win2003 Server with a SQL Server 2005 Express database. I connect to it via a MS Access application.
Since I switched to the new server (restored a backup from the former server on it) all SPROCs (only in Access) have a ;1 after their name, hence cannot be found.
If I try to open a SPROC in Access (dbl click in overview), it asks for the parameter, then says cannot be found.
If I try to open, say, a report based on it, same result. If I change the name of the SPROC the report is based on to the name shown in the overview ( [sprocnam];1 ) it says "cannot be found" (of course, because the names did not change as one can see in Management Studio).
?!?
keep in mind that the Access-application worked fine with the database that I backed up on another server and restored to the newly set up server ...
Your help is greatly appreciated!
edit: I found a thread on SAP.com with someone experiencing the same problem, but without a solution: https://forums.sdn.sap.com/message.jspa?messageID=7947957
I can't tell why you have got this issue, but in In SQL Server you have the ability to create Numbered stored procedures. The procedures have the same name but may contain completely different code, look at this:
CREATE PROCEDURE [dbo].[spTest]
AS
BEGIN
SELECT ##MICROSOFTVERSION
END
GO
CREATE PROCEDURE [dbo].[spTest];2
AS
SELECT ##version
GO
EXEC spTest;1
EXEC spTest;2
I resolved the issue with an update of the clients office-installation to the latest service pack.
The one employee that notified me of the problem and me got new computers last week, and thus did not have the latest updates.

Resources