Ax 2012 component existence in all layers and models - axapta

Can anybody help me how to find a component existence in all layers and models installed in that layer. i.e find all the layers and models in which a particular component(ax 2012) exists.
For example how to find all the layers and models in which CustTable exists.
Is there any class or table that stores this information.
please help me. Thanks in advance.

Comment is limited :(
Do you need to search through source code? Are you searching for merge candidates? Tell me your business requirement.
Here is the query returning elements that contains CustTable within selected models:
SELECT
me.Name ElementName
, Layer.Name Layer
, mm.Name ModelName
, ElementTypes.ElementTypeName
FROM ModelElement me
JOIN ModelElementData med
ON med.ElementHandle = me.ElementHandle
AND me.ParentHandle = 0 -- only root elements
JOIN ModelManifest mm
ON mm.ModelId=med.ModelId
JOIN Layer
ON Layer.Id = med.LayerId
JOIN ElementTypes
ON me.ElementType = ElementTypes.ElementType
WHERE EXISTS (
SELECT null
FROM ModelElement child
JOIN Sources s
ON s.SourceHandle = child.ElementHandle
AND s.LayerId = med.LayerId
AND child.RootHandle = med.ElementHandle
WHERE cast([SourceText] as nvarchar(max)) like '%CustTable%'
)
AND mm.Name IN ('Foundation','I4C')

You can try search within _model databese with next query (this searcehs all code references - table, class, form, dataset, ...):
SELECT TOP 1000 [SourceHandle]
, met.ElementTypeName
, ro.Name object
, me.Name method
, l.Name Layer
, mm.Name Model
, cast([SourceText] as nvarchar(max)) sourceTxt
FROM [Sources] s
join ModelElement me on me.ElementHandle=s.SourceHandle
join ElementTypes met on met.ElementType=me.ElementType
join ModelElement ro on ro.ElementHandle=me.RootHandle
left join ModelElementData med on med.ElementHandle=s.SourceHandle and med.LayerId=s.LayerId and med.ElementHandle=me.ElementHandle
left join Layer l on l.Id=s.LayerId
left join ModelManifest mm on mm.ModelId=med.ModelId
WHERE cast([SourceText] as nvarchar(max)) like '%CustTable%'
If you need all records, remove TOP 1000.

SELECT DISTINCT
ro.Name object,
ro.ElementType type,
l.Name Layer,
mm.Name Model
FROM Sources s
join ModelElement me on
me.ElementHandle = s.SourceHandle
join ElementTypes met
on met.ElementType = me.ElementType
join ModelElement ro
on ro.ElementHandle = me.RootHandle
left join ModelElementData med
on med.ElementHandle = s.SourceHandle
and med.LayerId = s.LayerId
and med.ElementHandle = me.ElementHandle
left join Layer l
on l.Id = s.LayerId
left join ModelManifest mm
on mm.ModelId = med.ModelId
where ro.Name = 'InventDim' order by mm.Name, ro.ElementType
In addition to the query suggested by the authors, a small change was made according to my requirement is giving the right results.

Related

Nopcommerce export user roles

I'm trying to get a list of ALL user roles for each user through the nopcommerce database. i just need the Customer.Id, Customer.Username, Customer.Email and Customer.Role (some have multiple roles)
This is all jacked up.
SELECT Customer.Id, Customer.Username, Customer.Email, CustomerRole.Name
FROM ((Customer
INNER JOIN CustomerRole ON CustomerRole.Id = Customer.Id)
INNER JOIN Customer_CustomerRole_Mapping ON Customer_CustomerRole_Mapping.CustomerRole_Id = CustomerRole.Id)
Any help is greatly appreciated!
I think you need a LEFT OTUER JOIN because in your DB can be user without role; in this case you can use this:
SELECT DISTINCT CUST.Id, CUST.Username, CUST.Email, CR.Id, CR.Name,
CCRM.CustomerRole_Id ,
FROM CUSTOMER CUST
LEFT OUTER JOIN Customer_CustomerRole_Mapping CCRM
ON CUST.ID = CCRM.Customer_Id
LEFT OUTER JOIN CustomerRole CR
ON CCRM.CustomerRole_Id = CR.Id
Also, you can have only one row per user with a column with his roles, like this:
SELECT DISTINCT CUST.Id, CUST.Username, CUST.Email,
Roles = STUFF((
SELECT ',' + CAST(CR1.Name as varchar(4000))
FROM CustomerRole CR1
LEFT OUTER JOIN Customer_CustomerRole_Mapping CCRM1
ON CCRM1.CustomerRole_Id = CR1.Id
LEFT OUTER JOIN CUSTOMER CUST1
ON CUST1.ID = CCRM1.Customer_Id
WHERE CUST1.Id = CUST.Id
FOR XML PATH('')
), 1, 1, '')
FROM CUSTOMER CUST
LEFT OUTER JOIN Customer_CustomerRole_Mapping CCRM
ON CUST.ID = CCRM.Customer_Id
LEFT OUTER JOIN CustomerRole CR
ON CCRM.CustomerRole_Id = CR.Id
Depending of your using, last query can be a little bit slow if you have a lot of customers.

Doctrine DQL with multiple joined tables

i have entities **target,citytarget,city,cityplace,place
citytarget & cityplace are pivot tables that connect t&c and c&p
i need the places for given city name and a target id
i tried the following DQL:
SELECT t,c,p FROM MulticatorBundle:Target t
join t.cities ct
join ct.cities c
join c.places cp
join cp.places p
where c.name like '%Stahmeln%'
But i receive:
result: The parent object of entity result with alias 'c' was not found. The parent alias is 'ct'.
i dont know any further....
a plain SQL could be:
select * from target
left join citytarget on citytarget.target_id = target.id
left join city on citytarget.city_id = city.id
left join cityplace on cityplace.city_id = city.id
left join place on cityplace.id = place.id
where target.id = 1
and city.name like \'%Stahmeln%\'
Adrian
You always need your parent entity in your select. In this case:
SELECT ct, c, cp, t, p
is needed
You need to do
SELECT t,ct, c, cp ,p FROM MulticatorBundle:Target t
join t.cities ct
join ct.cities c
join c.places cp
join cp.places p
where c.name like '%Stahmeln%'
Hope this help you

Merge 2 Tables Data in SQL

I have 3 Data Table Claim, Part and Labor.
In this Claim is parent table and Part and Labor is mapping tables of Claim and they have Part and Labor has the ClaimId as a Foreign Key.
Claim has data like:
Part has data Like
Labor table has data Like
Target Output would be:
Can anyone help me to achieve this in SQL server.
I have tried to solve with the Union/CTE but it did not gives the result as I want.
I got the same output (for your updated output screen) for this specific case. I don't know if any other data will work for you.
SELECT TMP.ClaimId
, CASE WHEN TMP.RowNum = 1 THEN TMP.Name ELSE NULL END AS ClaimName
, CASE WHEN TMP.RowNum = 1 THEN TMP.Note ELSE NULL END AS Note
, TMP.PartId
, TMP.PartNumber
, TMP.PartCost
, JOIN_L.LaborId
, JOIN_L.LaborCost
FROM (
SELECT C.ClaimId, C.Name, C.Note, P.PartId, P.PartNumber, P.PartCost
, ROW_NUMBER() OVER(PARTITION BY C.ClaimId ORDER BY P.PartId) AS RowNum
FROM Claim AS C
LEFT JOIN Part AS P ON C.ClaimId = P.ClaimId
)AS TMP
LEFT JOIN (
SELECT *
, ROW_NUMBER() OVER(PARTITION BY L.ClaimId ORDER BY L.ClaimId) AS RowNum
FROM Labor AS L
) AS JOIN_L ON (TMP.ClaimId = JOIN_L.ClaimId AND TMP.RowNum = JOIN_L.RowNum)
ORDER BY TMP.ClaimId
Not sure why you tried CTE here
Select C.ClaimId,C.name,C.Note,P.PartId,P.PartNumber,P.PartCost,L.LabourId,L.LabourCost
From Claim C
Left Outer Join Part P On P.ClaimId = C.ClaimId
Left Outer Join Labor L On L.ClaimId=C.ClaimId

Asp.Net multiple join tables issue from Sqldatasoruce Query Builder into one gridview

In Visual Studio 2010 with ASP.NET 4, I am trying to join several tables together to put the results in a gridview and details view with sqldatasource. In the sqldatasource wizard I have chosen to specify a custom SQL statement or stored procedure and then in the Query Builder to define complex queries such as JOINs, I have tried to generate a SQL statement to join the problem table with speficific columns from other tables. But when I try to test the query I get an error message which says "Cannot call methods on varchar". I am new to sql statements so please can you advise on what is wrong with the statement.
Here is the generated sql statement below
SELECT Problem.ProblemID, Problem.CustomerID, Problem.Summary,
Problem.DateLogged, Problem.DateUpdated, Status.Status, Priority.Priority,
Technician.Name, Technician.Surname, [Skill Group].[Skill Group],
HelpdeskOperator.Name AS Expr1,
HelpdeskOperator.Surname AS Expr2, Problem.NoteID, Problem.ResolutionID
FROM Problem
INNER JOIN Status ON Problem.StatusID = Status.Status.StatusID
INNER JOIN HelpdeskOperator ON
Problem.HelpdeskID = HelpdeskOperator.HelpdeskID AND Status.StatusID = HelpdeskOperator.StatusID
INNER JOIN Priority ON Problem.PriorityID = Priority.PriorityID
INNER JOIN [Skill Group] ON Problem.SkillGroupID = [Skill Group].SkillGroupID
INNER JOIN Technician ON Problem.ProblemID = Technician.ProblemID
AND Status.StatusID = Technician.StatusID AND
Priority.PriorityID = Technician.PriorityID
AND [Skill Group].SkillGroupID = Technician.SkillGroupID
Thank you in advance
Fixed your query:
SELECT p.ProblemID, p.CustomerID, p.Summary, p.DateLogged, p.DateUpdated, s.Status, pr.Priority, t.Name, t.Surname,
sg.* , ho.Name AS Expr1, ho.Surname AS Expr2, p.NoteID, p.ResolutionID
FROM Problem p
INNER JOIN Status s ON p.StatusID = s.StatusID
INNER JOIN HelpdeskOperator ho ON p.HelpdeskID = ho.HelpdeskID AND s.StatusID = ho.StatusID
INNER JOIN Priority pr ON p.PriorityID = pr.PriorityID
INNER JOIN [Skill Group] sg ON p.SkillGroupID = sg.SkillGroupID
INNER JOIN Technician t ON p.ProblemID = t.ProblemID AND s.StatusID = t.StatusID AND pr.PriorityID = t.PriorityID
AND sg.SkillGroupID = t.SkillGroupID
You had duplicate table identifier in your join clause Status.Status.StatusID
I doubt that your Skill Group table contains column [Skill Group] so changed it to return all values from Skill Group
I just think those were the errors, if not I will need more info about your query and table structure.
EDIT:
First it did not return anything for HelpdeskOperator, look at our query:
INNER JOIN HelpdeskOperator ho ON p.HelpdeskID = ho.HelpdeskID AND s.StatusID = ho.StatusID
that meanse that here is no such HelpdeskOperator record that is assigned to our problem AND statusid, so either problem id points to noexisting helpdeskoperator or statusid of
this operator is different that problem status id.
next is Skill Group
INNER JOIN [Skill Group] sg ON p.SkillGroupID = sg.SkillGroupID
again our problem point to no existing skill group
then Technican
INNER JOIN Technician t ON p.ProblemID = t.ProblemID AND s.StatusID = t.StatusID AND pr.PriorityID = t.PriorityID
AND sg.SkillGroupID = t.SkillGroupID
here is more work as more checks, technicas must be assigned to our problem with given status and priorityt and be in skill group, BUT our skill group is null? so to check if
there is technican for our problem remove AND sg.SkillGroupID = t.SkillGroupID so you get
INNER JOIN Technician t ON p.ProblemID = t.ProblemID AND s.StatusID = t.StatusID AND pr.PriorityID = t.PriorityID
and see if now we get any technican.
I hope this points you into right direction. You must be sure that there are matching record in every joining table.

Querying on count value having ()

I'm having difficulty with a query which displays records according to their fill rate.
For instance, a vacancy can have no bookings or some bookings. If a vacancy has bookings, they can be in the form of 'active [1]', 'pending [0]'. The query I have written so far works if the vacancy has booking records but I can't get it to work if it doesn't have booking records.
My query (which works) for vacancies with a booking is as follows:-
SELECT v.*, j.job_category_name, bu.business_unit_name
FROM vacancy v
INNER JOIN job_category j ON j.job_category_id = v.job_category_id
INNER JOIN business_unit bu ON bu.business_unit_id = v.business_unit_id
INNER JOIN booking b ON b.vacancy_id = v.vacancy_id
INNER JOIN booking_status bs ON bs.id = b.booking_status_id
WHERE
v.vacancy_status <> 'revoked' AND
v.vacancy_reference <> 'auto-generated booking' AND
v.business_unit_id IN (series of primary keys) AND
(bs.booking_status_type_id = 1 OR bs.booking_status_type_id = 2)
GROUP BY v.vacancy_id
HAVING v.vacancy_limit > count(b.booking_id)
ORDER BY v.vacancy_id DESC
I thought by changing the join of b and bs to LEFT JOIN would have worked, but it hasn't.
Any ideas?
Without a copy of your schema to work from, it's difficult to tell exactly, but when you changed booking and bookingstatus to LEFT JOINs, did you also modify your WHERE clause so that it read something like:
WHERE
v.vacancy_status <> 'revoked' AND
v.vacancy_reference <> 'auto-generated booking' AND
v.business_unit_id IN (series of primary keys) AND
(ISNULL(bs.booking_status_type_id, 1) = 1 OR ISNULL(bs.booking_status_type_id, 2) = 2)
i.e. Ensured that the full WHERE clause would be satisfied, thus not stripping out the records where all the values for columns from booking and bookingstatus were NULL?
Try LEFT OUTER JOIN for the tables for which the joins may return 0 matches.
For eg:- in your case have LEFT OUTER JOIN for b and bs and check

Resources