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

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.

Related

sqlite query to get instances were no items returned on join

I am querying the static backend db for a game I play (trying to keep up on my coding), and I am having an issue getting the full results that I want.
So the query that I have so far is:
select ms.security, mc.constellationName, mr.regionName, ms.solarSystemName, count(it.typename) as NumberOfBelts
from mapSolarSystems as ms
join mapConstellations as mc on ms.constellationID == mc.constellationID
join mapRegions as mr on ms.regionID == mr.regionID
join invItems as ii on ii.locationID = ms.solarSystemID
join invTypes as it on it.typeID == ii.typeID
where it.groupID = 9
group by solarSystemName
the problem comes when there are no rows where it.groupID == 9. What I need is for the count to return 0 and I can't for the life of me figure out how to get this to work.
I tried doing left outer join on the final join statement, but no joy.
Change the last join to a left join and set the condition in the on clause istead of the where clause:
select ms.security, mc.constellationName, mr.regionName, ms.solarSystemName, count(it.typename) as NumberOfBelts
from mapSolarSystems as ms
join mapConstellations as mc on ms.constellationID = mc.constellationID
join mapRegions as mr on ms.regionID = mr.regionID
join invItems as ii on ii.locationID = ms.solarSystemID
left join invTypes as it on it.typeID = ii.typeID and it.groupID = 9
group by solarSystemName

QueryBuilder - Use Select in an innerJoin

can someone help me.
I need to change my sql query to a querybuilder. I don't know how to use select inside a innerJoin.
Here my sql query:
SELECT
user.id,
analytic_youtube_demographic.age_group,
analytic_youtube_demographic.percentage
FROM
user
INNER JOIN user_youtube ON user_youtube.id = user.id
INNER JOIN analytic ON analytic.id = user_youtube.analytic_id
INNER JOIN analytic_youtube_demographic ON analytic_youtube_demographic.analytic_id = analytic.id
INNER JOIN
(
SELECT analytic_youtube_demographic.id as id, MAX(analytic_youtube_demographic.percentage) max
from user
INNER JOIN user_youtube ON user_youtube.id = user.id
INNER JOIN analytic ON analytic.id = user_youtube.analytic_id
INNER JOIN analytic_youtube_demographic ON analytic_youtube_demographic.analytic_id = analytic.id
GROUP BY user.id
) AS T ON analytic_youtube_demographic.percentage = T.max
WHERE analytic_youtube_demographic.age_group IN ('18-24')
Thanks a lot for your help.

Ax 2012 component existence in all layers and models

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.

Update field using inner join

I am trying to update a field in a table from another table using INNER JOIN. Here is the code:
UPDATE TestResults
INNER JOIN Distractors
ON TestResults.DistractorID = Distractors.ID
SET TestResults.DistractorValue = Distractors.DistractorValue
This does not work I don't know why! Any idea? When I run the query I get the following error
There was an error parsing the query. [ Token line number = 2,Token line offset = 1,Token in error = INNER ]
Not all databases support join syntax with update. And when they do, the syntax differs. Here is a way to do your query without an explicit join using standard SQL:
UPDATE TestResults
set DistractorValue = (select max(d.DistractorValue)
from Distractors d
where TestResults.DistractorValue = d.DistractorValue
)
where exists (select 1
from Distractors d
where TestResults.DistractorValue = d.DistractorValue
);
The max() is only needed if there could be more than one matching row.
The where is only needed if the join is intended to do filtering as well as matching.
UPDATE TestResults
SET TestResults.DistractorValue = Distractors.DistractorValue
FROM TestResults
INNER JOIN Distractors
ON TestResults.DistractorID = Distractors.ID
You use the Updated table in the Inner join clause
ex:
UPDATE TestResults
SET TestResults.DistractorValue = Distractors.DistractorValue
FROM TestResults INNER JOIN Distractors
ON TestResults.DistractorID = Distractors.ID

sqlite multiple table joining...how?

I have three tables doodhiya, doodhdata and cashdata.
I am trying to join these and fetch some needed data by this code but not succeed
SELECT dname,ddate,dmonth,dyear,dmilk,uid
FROM doodhiya
INNER JOIN doodhiya.dhid = doodhdata.ddhid
INNER JOIN doodhdata.dhid = cashdata.uid
WHERE (dname='$mik' AND dmonth='$mikdatem' AND dyear='$mikdatey')
ORDER BY ddate ASC
What I have to do?
You are missing the table name and the ON keyword in your join
SELECT dname,ddate,dmonth,dyear,dmilk,uid
FROM doodhiya
INNER JOIN doodhdata ON doodhiya.dhid = doodhdata.ddhid
INNER JOIN cashdata ON doodhdata.dhid = cashdata.uid
WHERE (dname='$mik' AND dmonth='$mikdatem' AND dyear='$mikdatey')
ORDER BY ddate ASC
A note on this part of the question:
Pls suggest me what I have to do
The syntax for a join is documented in the manual (and millions of SQL references in the web). So the best thing you can do the next time is to first consult the manual and/or a SQL reference.
SELECT retailername,
productname,
qty,
stock,
price,
discount
FROM temptablename,
productmaster,
retailermaster
WHERE temptablename.pid = productmaster.productid
AND temptablename.rid = retailermaster. retailercode
SELECT dname,
ddate,
dmonth,
dyear,
dmilk,
uid
FROM doodhdata,
cashdata
WHERE doodhiya.dhid = doodhdata.ddhid
AND doodhdata.dhid = cashdata.uid
AND dname='$mik'
AND dmonth='$mikdatem'
AND dyear='$mikdatey'
ORDER BY ddate ASC

Resources