Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: SQL Expression Error Post Reply Post New Topic
Author Message
vijayk
Groupie
Groupie


Joined: 14 Mar 2007
Location: United States
Online Status: Offline
Posts: 53
Quote vijayk Replybullet Topic: SQL Expression Error
     Posted: 17 Mar 2008 at 2:14pm

I am getting an error when I try to create the below SQL Statement in the SQL Expression.

"subquery returned more than 1 value. This is not permitted when the subquery is used an expression".
 
I know the query wouldnot get multiple values. Do you know what else i am doing wrong.
 
I am writing the following SQL Statement in the SQL Expression field.
 
(Select Distinct A.PID_WEK_NO from Table1 A Where getdate() BETWEEN A.PID_BGN_DT and A.PID_END_DT)
 
Thanks
Vijay 
 
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 17 Mar 2008 at 2:22pm
Have you executed this command and looked at the raw data it returns? Also, do you get the error when editing and saving the data or when running the report?
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
vijayk
Groupie
Groupie


Joined: 14 Mar 2007
Location: United States
Online Status: Offline
Posts: 53
Quote vijayk Replybullet Posted: 17 Mar 2008 at 2:36pm
Brian,
 
I dont understand how you get multiple values because i am using a distinct and I am saying get todays date and check the table to get the week info. So you are saying may be a data integrity issue. ?
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 17 Mar 2008 at 4:04pm
I've had more time to think look at this (it's a busy day). I think it needs to be clarified what a SQL Expression is. It is not a SELECT statement. A SQL expression field is a formula that uses SQL specific keywords. This will be inserted into the reports data source query (which is itself a SELECT statement). So a Sql Expression could be (FieldName * 1.5)/100. It's a formula. This will then get inserted into a SELECT statement as one of the fields to pull from the data. Thus, you can't have a SELECT statement in the SQL Expression b/c it will be part of the SELECT statement that Crystal Reports uses to query the database.

What you are doing here is pulling data as another data source which should be linked to the main data source that the report is printing from.

Does that help?
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
vijayk
Groupie
Groupie


Joined: 14 Mar 2007
Location: United States
Online Status: Offline
Posts: 53
Quote vijayk Replybullet Posted: 18 Mar 2008 at 8:12am

That helps. So, How do you implement Subquery in Crystal.?

Vijay
 
IP IP Logged
fusion
Groupie
Groupie


Joined: 12 Nov 2007
Location: United States
Online Status: Offline
Posts: 93
Quote fusion Replybullet Posted: 18 Mar 2008 at 8:26am

What are you trying to do using a subquery? You can generate a report using the query (Subquery) and then insert into the report as a subreport if that is what you are trying to accomplish.

 
IP IP Logged
vijayk
Groupie
Groupie


Joined: 14 Mar 2007
Location: United States
Online Status: Offline
Posts: 53
Quote vijayk Replybullet Posted: 18 Mar 2008 at 9:57am
Brian,
 
I did try the same select statement in the SQL expression window and it worked. I was using wrong dates and it was bringing back multiple records before.
 
Thanks for all the input
 
Vijay
 
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