Click here to Skip to main content
15,917,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have problem with the the select command in my crystal report. I need to use one field of the table under different names depending on the value of another field.
I have this code:

SQL
SELECT 
[NOVI.GBR as gbrnov], 
[NOVI.AB as abnov], 
[NALOG1.DATA as datanov],
[Min(NALOG1.POCKM) AS MinOfPOCKM], 
[Max(NALOG1.KRAJKM) AS MaxOfKRAJKM],
[(Max(NALOG1.KRAJKM)-Min(NALOG1.POCKM)) AS RAZLIKA], 
[(MAGACIN.KOL)/100 AS Potr100km], 
[MAGACIN.SIFRA], 
[(case when [MAGACIN.SIFRA]='0991000' then [MAGACIN.KOL] else null end as 'Gorivo'], 
[(case when [MAGACIN.SIFRA]='0993050' then [MAGACIN.KOL] else null end as 'Maslo'], 
[NOVI.DATAP AS poslprov], 
[NOVI.DATAS AS poslservis] 
FROM 
(NALOG1 INNER JOIN MAGACIN ON NALOG1.GBRV=MAGACIN.GBR) INNER JOIN NOVI ON NALOG1.GBRV=NOVI.GBR where ( ( ( (NOVI.GBR)>=? And (NOVI.GBR)<=? ) ) AND ( (NOVI.AB)=? or (NOVI.AB)=?) AND ( ( (NALOG1.DATA)>=?) and ((NALOG1.DATA)<=?) ) ) GROUP BY NOVI.GBR, NOVI.AB, NALOG1.DATA, NOVI.DATAP, NOVI.DATAS


and get the error IErrorInfo.GetDescription failed with E_FAIL(0x80004005)
Can anybody help me please, I am desperate and don't know what to do with this.
Posted
Updated 16-Nov-11 6:02am
v4

1 solution

It looks that there is some reserved words in your query. I suggest you replace table.field by [table].[field]
try this

SQL
SELECT 
[NOVI].[GBR] as gbrnov, 
[NOVI].[AB] as abnov, 
[NALOG1].[DATA] as datanov,
Min([NALOG1].[POCKM]) AS MinOfPOCKM, 
Max([NALOG1].[KRAJKM]) AS MaxOfKRAJKM,
Max([NALOG1].[KRAJKM])-Min([NALOG1].[POCKM]) AS RAZLIKA, 
([MAGACIN].[KOL])/100 AS Potr100km, 
[MAGACIN].[SIFRA], 
case when [MAGACIN].[SIFRA]='0991000' then [MAGACIN].[KOL] else null end as 'Gorivo', 
case when [MAGACIN].[SIFRA]='0993050' then [MAGACIN].[KOL] else null end as 'Maslo', 
[NOVI].[DATAP] AS poslprov, 
[NOVI].[DATAS] AS poslservis 
FROM 
(NALOG1 INNER JOIN MAGACIN
ON [NALOG1].[GBRV] =[MAGACIN].[GBR])
INNER JOIN [NOVI] ON [NALOG1].[GBRV] = [NOVI].[GBR] where
( ( ( ([NOVI].[GBR])>=? And ([NOVI].[GBR])<=? ) )
AND ( ([NOVI].[AB])=? or ([NOVI].[AB])=?)
AND ( (([NALOG1].[DATA])>=?)
and (([NALOG1].[DATA])<=?) ) )
GROUP BY [NOVI].[GBR], [NOVI].[AB], [NALOG1].[DATA], [NOVI].[DATAP], [NOVI].[DATAS]
 
Share this answer
 
Comments
nat06 16-Nov-11 14:48pm    
I tried like this, but again the same error occured.
Is there any other way how to select a field (column) from table that is given by me and to assign values from the other column (column1), which depends on the values of the column2?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900