Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Friday, May 3, 2024 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Data & Imports Forums - T-SQL & Queries
Forum to discuss general T-SQL questions and help with queries related to SalesLogix data. View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to T-SQL & Queries | New ThreadView:  Search:  
 Author  Thread: Qry help for joining tables
Renee Bender
Posts: 74
 
Qry help for joining tablesYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 24 Sep 08 1:41 PM
I hope someone can help me with this. I have a qry that I can run in Query Analyzer but I cannot get it to run in Saleslogix. I keep getting a Failed to Parse error whenever I add that last "Left Join". I don't get the error if I leave off the "Left", but I do get it when I add it in. Also, when it does run, it should give me back 1 record for all of the data in the account_serviceagreem file with a column for contactname that is null. It isn't giving me any data. Can someone please look at this and tell me what I am doing wrong?

strSQL = "SELECT distinct s.*, (c.firstname + ' ' + c.lastname) as contactname, c.workphone "&_
"FROM account_serviceagreem s "&_
"LEFT OUTER JOIN account_misc a on s.parent_no = a.parent "&_
"LEFT JOIN contact_account_role r on a.accountid = r.account_id and r.contact_type = 'L' "&_
"LEFT JOIN contact c on c.accountid = r.account_id and c.contactid = r.contact_id "&_
"WHERE s.account_serviceagreemID = '"& strVal &"' and a.Parent = '"& strVal2 &"' and a.cmcust = '"& strVal2 &"' "

Thanks,
Renee
[Reply][Quote]
Shawn O'Ferrall
Posts: 21
 
Re: Qry help for joining tablesYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 25 Sep 08 7:07 AM
I think the problem is the extra 'where' in one of you joins. Try this:

strSQL = "SELECT distinct s.*, (c.firstname + ' ' + c.lastname) as contactname, c.workphone "&_
"FROM account_serviceagreem s "&_
"LEFT OUTER JOIN account_misc a on s.parent_no = a.parent "&_
"LEFT JOIN contact_account_role r on a.accountid = r.account_id "&_
"LEFT JOIN contact c on c.accountid = r.account_id and c.contactid = r.contact_id "&_
"WHERE r.contact_type = 'L' and s.account_serviceagreemID = '"& strVal &"' and a.Parent = '"& strVal2 &"' and a.cmcust = '"& strVal2 &"' "
[Reply][Quote]
Renee Bender
Posts: 74
 
Re: Qry help for joining tablesYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 25 Sep 08 8:15 AM
I tried what you suggested but I still received the same error. If I remove the "left" from the last join I don't get the error, but I am not getting the results that I want. I still want to get back the data from the account_serviceagreem table even if there is no contact with contact_type 'L' in the contact_account_role table. My sql only seems to return a record if there is a contact with 'L' type. Any other suggestions???
Thank you very much for your help!
Renee
[Reply][Quote]
Stephen Redmond
Posts: 190
 
Re: Qry help for joining tablesYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 25 Sep 08 7:17 PM
Hi Renee,

Your original query appears to be fine. However, just double check that the values in your "WHERE" clause will actually return rows from the account_serviceagreem and account_misc tables. If they don't then the contact role not being "L" will not matter at all because you will get no rows.

I don't know your logic but the thing that looks suspicious to me is that you use the strVal2 field for 2 comparisons - is that right?


Stephen
[Reply][Quote]
Paul Cannon
Posts: 23
 
Re: Qry help for joining tablesYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 26 Sep 08 9:22 AM
We've experienced similar issues where queries work fine in SQL QA but not through the Provider.

Is there a Provider issue here?
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2024 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 5/3/2024 9:10:47 AM