Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: syntax error in sql query Post Reply Post New Topic
Author Message
Macavity
Groupie
Groupie


Joined: 24 Sep 2012
Online Status: Offline
Posts: 93
Quote Macavity Replybullet Topic: syntax error in sql query
     Posted: 10 Jun 2015 at 4:19am
Hi,

I get a syntax error in a command, I can't see what it is :

select

cast(substr(Code,7,9) as char(9)) as Ordercode from table

The actual problem : this field does appear in the field explorer, but not in the links tab, which means that Crystal doesn't recognize the data type. I tried to_char and to_text, that doesn't work. Now I'm trying with CAST
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 10 Jun 2015 at 4:35am
what data type is CODE?
IP IP Logged
Macavity
Groupie
Groupie


Joined: 24 Sep 2012
Online Status: Offline
Posts: 93
Quote Macavity Replybullet Posted: 10 Jun 2015 at 5:35am
It's supposed to be text. other substrings from Code do appear in the link tab, except OrderCode

to_number(subrstr(Code,10,2)) as Orderline doesn't give any syntax errors and shows in the link tab.


IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 10 Jun 2015 at 5:40am
and you tried without a cast or convert?
 
substr(Code,7,9) as Ordercode from table
 


Edited by DBlank - 10 Jun 2015 at 5:51am
IP IP Logged
Macavity
Groupie
Groupie


Joined: 24 Sep 2012
Online Status: Offline
Posts: 93
Quote Macavity Replybullet Posted: 10 Jun 2015 at 7:04am
Yes, that doesn't give any syntax errors, but OrderCode doesn't appear in the links tab, I need that field to link to a table
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 10 Jun 2015 at 7:12am
what is your source data type?
IP IP Logged
Macavity
Groupie
Groupie


Joined: 24 Sep 2012
Online Status: Offline
Posts: 93
Quote Macavity Replybullet Posted: 10 Jun 2015 at 7:50am
The report (not written by me) connects with something ending with .uld. I don't know what that is. I was told it was one long string (field Code)
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 10 Jun 2015 at 8:11am

I am not sure as my testing  has not giving me any issues in a command object and a substring and using the resulting value as linkable field.

Maybe try a varchar?
CONVERT(Varchar(9),substring(Code,7,9)) as Ordercode from table
IP IP Logged
Macavity
Groupie
Groupie


Joined: 24 Sep 2012
Online Status: Offline
Posts: 93
Quote Macavity Replybullet Posted: 11 Jun 2015 at 1:38am
Convert doesn't work either. I found a solution. I created a subreport with the table that has field Code. Unfortunately in the subreport link Ordercode didn't appear (frustrating). I created a formula in the subreport :
command.ordercode + " ". That field appeared in the subreport link. Problem solved, not very neat, but oh well.....
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