CONVERT SQL STATEMENT INTO FETCH - BASED XML
-
Tuesday, May 15, 2012 6:17 PM
I'm a newbie with fetch based XML. Can somebody give me some hints what I should do to get the SQL Statement below converted to fetch - based XML. Help will be much appreciated. :-)
SELECT TOP (10000) dbo.FilteredAccount.territoryidname AS Territory, dbo.FilteredOpportunity.owneridname AS Owner, dbo.FilteredOpportunity.name AS Topic,
dbo.FilteredOpportunity.customeridname AS [Potential Customer], dbo.FilteredOpportunity.new_contactpersonidname AS Contactperson,
dbo.FilteredOpportunity.statuscodename AS StatusFase, dbo.FilteredOpportunity.statecodename AS Status, dbo.FilteredOpportunity.createdbyname AS [Created By],
dbo.FilteredOpportunity.createdon AS [Created On], dbo.FilteredOpportunity.modifiedbyname AS [Modified By], dbo.FilteredOpportunity.modifiedon AS [Modified On],
dbo.FilteredOpportunity.estimatedclosedate AS [Est. Close Date], dbo.FilteredOpportunity.actualclosedate AS [Actual Close Date],
dbo.FilteredOpportunityProduct.opportunityid AS LinjeId, dbo.FilteredOpportunity.opportunityid,
dbo.FilteredOpportunityProduct.transactioncurrencyidname AS Currency, dbo.FilteredOpportunity.isrevenuesystemcalculatedname AS Revenue,
dbo.FilteredOpportunityProduct.productid AS ProductId, dbo.FilteredOpportunityProduct.productidname AS [Product Name],
dbo.FilteredOpportunityProduct.quantity AS Quantity, dbo.FilteredOpportunityProduct.exchangerate AS Exchangerate,
dbo.FilteredOpportunityProduct.baseamount AS Baseamount, dbo.FilteredOpportunityProduct.baseamount_base AS Baseamount_Base,
dbo.FilteredOpportunityProduct.extendedamount AS ExtendedAmount, dbo.FilteredOpportunityProduct.extendedamount_base AS ExtendedAmount_Base,
dbo.FilteredOpportunityProduct.new_costprice AS New_Costprice, dbo.FilteredOpportunityProduct.new_costprice_base AS New_Costprice_Base,
dbo.FilteredOpportunityProduct.new_discount AS New_Discount, dbo.FilteredOpportunityProduct.new_discount_base AS New_Discount_Base,
dbo.FilteredOpportunityProduct.new_listprice AS New_Listprice, dbo.FilteredOpportunityProduct.new_listprice_base AS New_Listprice_Base,
dbo.FilteredOpportunityProduct.new_priceoverridden AS Ndew_Priceoverridden,
dbo.FilteredOpportunityProduct.new_priceoverriddenname AS New_Priceoverridden_Base, dbo.FilteredOpportunityProduct.new_priceperunit AS Nrew_Priceperunit,
dbo.FilteredOpportunityProduct.new_priceperunit_base AS New_Priceperunit_Base, dbo.FilteredOpportunityProduct.priceperunit AS Priceperunit,
dbo.FilteredOpportunityProduct.priceperunit_base AS Priceperunit_Base, dbo.FilteredOpportunityProduct.tax AS Tax,
dbo.FilteredOpportunityProduct.tax_base AS Tax_Base, dbo.FilteredOpportunityProduct.tax AS Expr1, dbo.FilteredOpportunityProduct.tax_base AS Expr2,
dbo.FilteredOpportunityProduct.productdescription, dbo.FilteredOpportunityProduct.owninguser, dbo.FilteredOpportunityProduct.owningbusinessunit,
dbo.FilteredOpportunityProduct.pricingerrorcodename AS [Pricing Error Code Name], dbo.FilteredOpportunityProduct.uomidname AS Unit,
dbo.FilteredProduct.producttypecodename
FROM dbo.FilteredAccount INNER JOIN
dbo.FilteredOpportunity ON dbo.FilteredAccount.accountid = dbo.FilteredOpportunity.accountid AND
dbo.FilteredAccount.accountid = dbo.FilteredOpportunity.accountid INNER JOIN
dbo.FilteredOpportunityProduct ON dbo.FilteredOpportunity.opportunityid = dbo.FilteredOpportunityProduct.opportunityid INNER JOIN
dbo.FilteredProduct ON dbo.FilteredOpportunityProduct.productid = dbo.FilteredProduct.productidHans Inge
All Replies
-
Tuesday, May 15, 2012 6:51 PMI prefer you to use Advance find and download your fetch XML.
Go to Advanced Find, create your query and select “Download FetchXML”. Just cut and paste it into your code.
I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
Mubasher Sharif
Check out my about.me profile!
http://mubashersharif.blogspot.com
Linked-In Profile
Follow me on Twitter!
- Edited by MubasherSharif Tuesday, May 15, 2012 6:56 PM
-
Tuesday, May 15, 2012 7:02 PM
Hi,
If you look at the criteria below you'll see that i cannot use your suggestion. Correct me if I'm wrong.
FROM dbo.FilteredAccount INNER JOIN
dbo.FilteredOpportunity ON dbo.FilteredAccount.accountid = dbo.FilteredOpportunity.accountid AND
dbo.FilteredAccount.accountid = dbo.FilteredOpportunity.accountid INNER JOIN
dbo.FilteredOpportunityProduct ON dbo.FilteredOpportunity.opportunityid = dbo.FilteredOpportunityProduct.opportunityid INNER JOIN
dbo.FilteredProduct ON dbo.FilteredOpportunityProduct.productid = dbo.FilteredProduct.productidHans Inge
-
Tuesday, May 15, 2012 7:55 PMRemember fetchXML has some limitations.
- You cannot specify left outer joins – e.g. The following is not supported: “Select all Accounts who do not have a related Completed Appointment record”
- You cannot specify group by / sum queries – e.g. The following is not supported: “Select Account Name, count(*), sum(est. value) from Account Group By Account Name” – You can only select the records in detail and then perform the aggregation in your report. But…
- Fetch XML queries return a maximum of 5000 records.
To convert your above query please check the following blog
http://community.dynamics.com/product/crm/crmtechnical/b/crminogic/archive/2010/04/09/fetchxml-v-47-s-queryexpression.aspxI hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
Mubasher Sharif
Check out my about.me profile!
http://mubashersharif.blogspot.com
Linked-In Profile
Follow me on Twitter!