Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Using a complex SQL command with parameters Post Reply Post New Topic
Author Message
Morris
Newbie
Newbie


Joined: 29 Aug 2012
Online Status: Offline
Posts: 6
Quote Morris Replybullet Topic: Using a complex SQL command with parameters
     Posted: 15 Oct 2012 at 1:03am

Hoping someone out there has encountered this before. I am writing report using a command. The issues is that I want it to run off a different database depending on a parameter. This command works fine in SQL Query but am getting column name errors in Crystal.

 
Any ideas please?
 
Query is as follows:
 

declare @dbname nvarchar(255);

set @dbname = {?CONAME};

if @dbname = 'ZZZZ Training ???? ZZZZZZ ' use TRNDAT;

else if @dbname = ???' use ZWMDAT;

/*DROP TABLE #GSR_GL */

declare @YEAR CHAR(4)

declare @PERIOD CHAR(2)

set @year = '2012'

set @period = '10'

CREATE TABLE #GSR_GL

(ACCTID CHAR(15),

FYEAR CHAR(4),

PERIOD CHAR(2),

SRCECURN CHAR(3),

SRCELEDGER CHAR(2),

SRCETYPE CHAR(2),

JRNLDATE CHAR(8),

JRNLDTLDESC CHAR(100),

JRNLDTLREF CHAR(50),

TRANSAMT DECIMAL(19,3)

)

INSERT INTO #GSR_GL

select LEFT(ACCTID,6)+'-'+RIGHT(LEFT(ACCTID,9),3)+'-'+RIGHT(LEFT(ACCTID,12),3) AS ACCTID, FISCALYR, FISCALPERD, SRCECURN,

SRCELEDGER, SRCETYPE, JRNLDATE, JNLDTLDESC, JNLDTLREF, TRANSAMT from GLPOST

where left(ACCTID,3) = '080'

AND FISCALYR = @YEAR AND FISCALPERD = @PERIOD

select * from #GSR_GL

IP IP Logged
Sastry
Moderator
Moderator
Avatar

Joined: 16 Jul 2012
Online Status: Offline
Posts: 537
Quote Sastry Replybullet Posted: 15 Oct 2012 at 3:03am
Hi
 
I don't find the folling columns in your table creation . 
 
FISCALYR, FISCALPERD,
 
May be it could be the reason
 
 
Thanks,
Sastry
IP IP Logged
Morris
Newbie
Newbie


Joined: 29 Aug 2012
Online Status: Offline
Posts: 6
Quote Morris Replybullet Posted: 15 Oct 2012 at 3:45am
Thanks Sastry. FISCALYR and FISCALPERD are in the GLPOST table that the select query is reading from.
 
The query runs perfectly in SQL query. Just when I try to put it into crystal.
 
Probably because I'm trying to specify a different database in the SQL to what is used in the report?
 
Not sure how to get around that....
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum