Hi Codeignitier Expert i need help i have error
<h1>A Database Error Occurred</h1>
<p>Error Number: 42000/102</p><p>[Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near 'c'.</p><p>select a.norm, b.nama as pasien, b.alamat, c.tanggal, c.tanggal1, f.jumlah, f.biaya from TTKunjungan a inner join TMPasien b on A.norm = b.norm inner join TTKunjunganDetail c on A.Kode = c.kodekunjungan inner join TMTrfTindakan d on c.kodetindakan = d.Kode inner join TMTrfLayanan e on d.kodelayanan = e.Kode left join (select kodett, sum(jumlah) as jumlah, sum(biaya) as biaya from TTKunjunganDetail where kodett is not null group by kodett) f on c.Kode = F.kodett Where e.kodeklasifikasi = 2 and c.tanggal1 is null and c.kodett is null c.kodetindakan = '2161000011610000316100001'</p><p>Filename: D:/andi/xampp/htdocs/Simrsgum/system/database/DB_driver.php</p><p>Line Number: 664</p></div
this is my sql command
public function get_by_id1($Kode)
{
$tSQL = "select a.norm, b.nama as pasien, b.alamat, c.tanggal, c.tanggal1, f.jumlah, f.biaya from TTKunjungan a inner join TMPasien b on A.norm = b.norm inner join TTKunjunganDetail c on A.Kode = c.kodekunjungan inner join TMTrfTindakan d on c.kodetindakan = d.Kode inner join TMTrfLayanan e on d.kodelayanan = e.Kode left join (select kodett, sum(jumlah) as jumlah, sum(biaya) as biaya from TTKunjunganDetail where kodett is not null group by kodett) f on c.Kode = F.kodett Where e.kodeklasifikasi = 2 and c.tanggal1 is null and c.kodett is null c.kodetindakan = '{$Kode}'";
$list = $this->db->query($tSQL);
$query = $this->db->get();
return $query->num_rows();
}
can u help me to show where my sintax error pls....
Related
I have a SQL Statement like this:
select
b.ActivityRecordId, b.ActivityName, b.ActivityDetail,
b.CustomerId, e.CustomerName,
b.JobStatusId, c.JobStatusName, b.EstimateStartDate,
b.EstimateFinishDate, b.StartedDateTime, b.FinishedDateTime,
a.ActivityRecordProgressId, a.CustomerContactId,
Concat(d.FirstName, ' ', d.MiddleName, ' ', d.LastName) as fullName,
a.Started, a.Finished, a.ActivityDescription,
g.ActivityTypeId, g.ActivityTypeName, a.ActivitySubTypeId, f.ActivitySubTypeName
from
ActivityRecordProgress a
right join
ActivityRecord b on a.ActivityRecordId = b.ActivityRecordId
left join
ActivitySubType f on a.ActivitySubTypeId = f.ActivitySubTypeId
left join
ActivityType g on f.ActivityTypeId = g.ActivityTypeId
left join
CustomerContact d on a.CustomerContactId = d.CustomerContactId
inner join
JobStatus c on b.JobStatusId = c.JobStatusId
inner join
Customer e on b.CustomerId = e.CustomerId
Then I tried to convert it to Linq:
var obj = (from a in _db.ActivityRecords
join b in _db.ActivityRecordProgresses on a.ActivityRecordId equals b.ActivityRecordId into ab
from p in ab.DefaultIfEmpty()
join c in _db.Customers on a.CustomerId equals c.CustomerId
join e in _db.CustomerContacts on c.CustomerId equals e.CustomerId
join d in _db.JobStatuses on a.JobStatusId equals d.JobStatusId
join f in _db.ActivitySubTypes on p.ActivitySubTypeId equals f.ActivitySubTypeId
join g in _db.ActivityTypes on f.ActivitySubTypeId equals g.ActivityTypeId
select new OutstandingActivityViewModel {
ActivityRecordId = p.ActivityRecordId,
ActivityName = a.ActivityName,
ActivityDetail = a.ActivityDetail,
CustomerId = a.CustomerId,
CustomerName = c.CustomerName,
JobStatusId = a.JobStatusId,
JobStatusName = d.JobStatusName,
EstimateStartDate = a.EstimateStartDate,
StartedDateTime = a.StartedDateTime,
EstimateFinishDateTime = a.EstimateFinishDate,
FinishedDateTime = a.FinishedDateTime,
FirstName = e.FirstName, MiddleName = e.MiddleName, LastName = e.LastName,
Started = p.Started, Finished = p.Finished,
ActivityTypeName = g.ActivityTypeName, ActivitySubTypeName = f.ActivitySubTypeName,
ActivityDescription = p.ActivityDescription
}).ToListAsync();
But the result is not the same. The SQL result is the right one. It only 4 records. But in Linq, it appears 6 records. I'm sure I did something wrong with the linq syntax.
Can anyone show me where the mistake in my syntax is?
Really appreciated - thank you.
Thanks for commenting my question. It was very useful.
Finally I found the answer after trial and error using SQL generated. Below is the answer for the Linq syntax:
var obj = (from a in _db.ActivityRecords
join b in _db.ActivityRecordProgresses on a.ActivityRecordId equals b.ActivityRecordId into leftsatu
from leftkesatu in leftsatu.DefaultIfEmpty()
join c in _db.ActivitySubTypes on leftkesatu.ActivitySubTypeId equals c.ActivitySubTypeId into leftdua
from leftkedua in leftdua.DefaultIfEmpty()
join d in _db.ActivityTypes on leftkedua.ActivitySubTypeId equals d.ActivityTypeId into lefttiga
from leftketiga in lefttiga.DefaultIfEmpty()
join e in _db.CustomerContacts on leftkesatu.CustomerContactId equals e.CustomerContactId into leftempat
from leftkeempat in leftempat.DefaultIfEmpty()
join f in _db.JobStatuses on a.JobStatusId equals f.JobStatusId
join g in _db.Customers on a.CustomerId equals g.CustomerId
select new OutstandingActivityViewModel
{
ActivityRecordId = a.ActivityRecordId,
ActivityName = a.ActivityName,
ActivityDetail = a.ActivityDetail,
CustomerId = a.CustomerId,
CustomerName = g.CustomerName,
JobStatusId = a.JobStatusId,
JobStatusName = f.JobStatusName,
EstimateStartDate = a.EstimateStartDate,
StartedDateTime = a.StartedDateTime,
EstimateFinishDateTime = a.EstimateFinishDate,
FinishedDateTime = a.FinishedDateTime,
FirstName = leftkeempat.FirstName,
MiddleName = leftkeempat.MiddleName,
LastName = leftkeempat.LastName,
Started = leftkesatu.Started,
Finished = leftkesatu.Finished,
ActivityTypeName = leftketiga.ActivityTypeName,
ActivitySubTypeName = leftkedua.ActivitySubTypeName,
ActivityDescription = leftkesatu.ActivityDescription
}
);
It will generate SQL like:
SELECT [a].[ActivityRecordId], [a].[ActivityName], [a].[ActivityDetail], [a].[CustomerId], [c0].[CustomerName], [a].[JobStatusId], [j].[JobStatusName],
[a].[EstimateStartDate], [a].[StartedDateTime], [a].[EstimateFinishDate] AS [EstimateFinishDateTime], [a].[FinishedDateTime],
[c].[FirstName], [c].[MiddleName], [c].[LastName],
[a0].[Started], [a0].[Finished], [a2].[ActivityTypeName], [a1].[ActivitySubTypeName], [a0].[ActivityDescription]
FROM [ActivityRecord] AS [a]
LEFT JOIN [ActivityRecordProgress] AS [a0] ON [a].[ActivityRecordId] = [a0].[ActivityRecordId]
LEFT JOIN [ActivitySubType] AS [a1] ON [a0].[ActivitySubTypeId] = [a1].[ActivitySubTypeId]
LEFT JOIN [ActivityType] AS [a2] ON [a1].[ActivitySubTypeId] = [a2].[ActivityTypeId]
LEFT JOIN [CustomerContact] AS [c] ON [a0].[CustomerContactId] = [c].[CustomerContactId]
INNER JOIN [JobStatus] AS [j] ON [a].[JobStatusId] = [j].[JobStatusId]
INNER JOIN [Customer] AS [c0] ON [a].[CustomerId] = [c0].[CustomerId]
I'm struggling with this SQL consult, the error message is:
1055 - Expression #10 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'ctrl2019.s.cgsc_cuenta' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by.
And here is the code:
SELECT c.cgcu_cuenta AS id,
g.ger_cuenta, g.ger_nombre,
p.cgp_cuenta, p.cgp_nombre,
r.rub_cuenta, r.rub_nombre,
c.cgcu_cuenta, c.cgcu_nombre,
s.cgsc_cuenta, s.cgsc_nombre,
SUM(IFNULL(a.debe, 0)) - SUM(IFNULL(a.haber, 0)) AS debe, 0 AS haber,
'D' AS nat_id,
c.cgcu_cuenta AS cuenta, c.cgcu_nombre AS nombre
FROM ctrl2019.cat_Genero g
INNER JOIN ctrl2019.cat_CgGrupo p USING(ger_id)
INNER JOIN ctrl2019.cat_Rubro r USING(ger_id, cgp_id)
INNER JOIN ctrl2019.cat_CgCuenta c USING(ger_id, cgp_id, rub_id)
INNER JOIN ctrl2019.cat_CgSubcuenta s USING(ger_id, cgp_id, rub_id, cgcu_id)
LEFT JOIN (
SELECT a.ger_id, a.grp_id, a.rub_id, a.cta_id, a.sct_id,
SUM(IFNULL(a.msl_debe, 0)) AS debe, SUM(IFNULL(a.msl_haber, 0)) AS haber
FROM ldf.vin_EntePublicoLDF e
INNER JOIN ldf.blz_Mensual_2019 a USING(gpo_id, ur_id)
WHERE e.ejr_id = 2019
AND a.ger_id = 1
AND e.ent_id = 12
AND a.msc_id IN (0, 1, 2, 3)
GROUP BY a.ger_id, a.grp_id, a.rub_id, a.cta_id, a.sct_id
)a ON s.ger_id = a.ger_id AND s.cgp_id = a.grp_id AND s.rub_id = a.rub_id AND s.cgcu_id = a.cta_id AND s.cgsc_id = a.sct_id
WHERE g.ger_id = 1
GROUP BY g.ger_id, p.cgp_id, r.rub_id, c.cgcu_id;
I have no idea why it gives me this error, i'm new in sql.
you just need to add all the columns in GROUP BY which are present in the SELECT statement.
Seems like simple aggregation here. I cleaned up the code and added some columns to the GROUP BY.
SELECT
id = c.cgcu_cuenta
,g.ger_cuenta
,g.ger_nombre
,p.cgp_cuenta
,p.cgp_nombre
,r.rub_cuenta
,r.rub_nombre
,c.cgcu_cuenta
,c.cgcu_nombre
,s.cgsc_cuenta
,s.cgsc_nombre
,debe = SUM(IFNULL(a.debe, 0)) - SUM(IFNULL(a.haber, 0))
,haber = 0
,nat_id = 'D'
,cuenta = c.cgcu_cuenta
,nombre = c.cgcu_nombre
FROM ctrl2019.cat_Genero g
INNER JOIN ctrl2019.cat_CgGrupo p ON USING(ger_id)
INNER JOIN ctrl2019.cat_Rubro r ON USING(ger_id, cgp_id)
INNER JOIN ctrl2019.cat_CgCuenta c USING(ger_id, cgp_id, rub_id)
INNER JOIN ctrl2019.cat_CgSubcuenta s USING(ger_id, cgp_id, rub_id, cgcu_id)
LEFT JOIN (
SELECT
a2.ger_id
,a2.grp_id
,a2.rub_id
,a2.cta_id
,a2.sct_id
,debe = SUM(IFNULL(a2.msl_debe, 0))
,haber = SUM(IFNULL(a2.msl_haber, 0))
FROM ldf.vin_EntePublicoLDF E
INNER JOIN ldf.blz_Mensual_2019 a2 USING(gpo_id, ur_id)
WHERE e.ejr_id = 2019
AND a2.ger_id = 1
AND e.ent_id = 12
AND a2.msc_id IN (0, 1, 2, 3)
GROUP BY
a2.ger_id
,a2.grp_id
,a2.rub_id
,a2.cta_id
,a2.sct_id
) A
ON s.ger_id = A.ger_id
AND s.cgp_id = A.grp_id
AND s.rub_id = A.rub_id
AND s.cgcu_id = A.cta_id
AND s.cgsc_id = A.sct_id
WHERE g.ger_id = 1
GROUP BY
g.ger_id
,p.cgp_id
,r.rub_id
,C.cgcu_id
,c.cgcu_cuenta
,g.ger_cuenta
,g.ger_nombre
,p.cgp_cuenta
,p.cgp_nombre
,r.rub_cuenta
,r.rub_nombre
,c.cgcu_nombre
,s.cgsc_cuenta
,s.cgsc_nombre
I have a query according to the :
SELECT
tblDefinition.TopsisType, tblTemplate.tType, tblEvaluationFormCategory.Title AS EvaluationCategory,
CASE tType WHEN 1 THEN N'2'
ELSE N'1' END ProcessType,
tblDefinition.Description, tblDefinition.TemplateID, 1 Destinition
FROM tblTemplate INNER JOIN
tblEvaluationFormCategory ON tblTemplate.CategoryID = tblEvaluationFormCategory.ID INNER JOIN
tblEFQMAlternative INNER JOIN
tblDefinition ON ([tblEFQMAlternative].[TopsisID] = [tblDefinition].[TopsisID] AND [tblEFQMAlternative].[CustomerID] = [tblDefinition].[CustomerID]) INNER JOIN
tblGroupMembers ON ([tblDefinition].[TopsisID] = [tblGroupMembers].[TopsisID]
AND tblDefinition.CustomerID =
tblGroupMembers.CustomerID) ON tblTemplate.TemplateID = tblDefinition.TemplateID
INNER JOIN
tblTerm ON tblDefinition.TermGrant = tblTerm.Title
WHERE (tblTerm.ID = 20) AND (tblGroupMembers.UserID = 558)
GROUP BY tblDefinition.TopsisType, tblTemplate.tType, tblEvaluationFormCategory.Title,
tblDefinition.Description, tblDefinition.TemplateID
when i convert to linq, then error to :
Field [([tblDefinition].[TopsisID] = [tblGroupMembers]].[[TopsisID] AND tblDefinition.CustomerID = tblGroupMembers.CustomerID) ON tblTemplate.TemplateID] not found in the current Data Context.
What should I do?
I have to change a query, and want to add some pre-defined results (outputs) to the query when two values are found on two different columns.
Basically I want to add values to a new column on a query. I tried to use CASE but no luck until now.
SELECT DISTINCT
Q1.SCHD_ID,
Q1.SCHD_DESC,
Q1.TIMEZONE_ID,
Q1.DISPLAY_IN_SCHD_TZ,
Q1.LOGO_ID,
Q1.CODICE_SKOFF,
Q1.CODICE_MODULO,
case
when (Q1.PIANO_CODICE = 'FND001' AND Q1.CODICE_SKOFF = '2346') THEN 'testA'
WHEN (Q1.PIANO_CODICE = 'FND001' AND Q1.CODICE_SKOFF = '2347') THEN 'testB'
WHEN (Q1.PIANO_CODICE = 'FND001' AND Q1.CODICE_SKOFF = '3287') THEN 'testC'
WHEN (Q1.PIANO_CODICE = 'FND001' AND Q1.CODICE_SKOFF = '0000') THEN 'testD'
WHEN (Q1.PIANO_CODICE = 'TEST' AND Q1.CODICE_SKOFF = '4435') THEN 'testE'
ELSE 'NULL'
END as TITOLO_MODULO_SO
FROM
(SELECT
sc.SCHD_ID,
sc.SCHD_DESC,
sc.TIMEZONE_ID,
sc.DISPLAY_IN_SCHD_TZ,
SUBSTR(su1.USER_VALUE, 1 ,3) as LOGO_ID,
su1r.USER_DESC as PIANO_FINANZIAMENTO,
su1r.USER_ID as PIANO_CODICE,
cu1.USER_VALUE as TITOLO_MODULO,
cu2.USER_VALUE as CODICE_MODULO,
c.CPNT_TITLE as ARGOMENTO,
sr.START_DTE,
sr.END_DTE,
cu3.USER_VALUE as DURATA_CORSO,
su4.USER_VALUE as CODICE_SKOFF
FROM PA_SCHED sc
-- Campo "Piano principale di finanziamento"
left outer join PA_SCHED_USER su1 on sc.SCHD_ID = su1.SCHD_ID and su1.COL_NUM = 50
left outer join PA_USRRF_SCHED su1r on su1r.COL_NUM = su1.COL_NUM and su1.USER_VALUE = su1r.USER_ID
-- Informazioni ITEM
left outer join PA_CPNT c on c.CPNT_TYP_ID = sc.CPNT_TYP_ID and c.CPNT_ID = sc.ACT_CPNT_ID and c.REV_DTE = sc.REV_DTE
-- ITEM -> Titolo per finanziamenti
left outer join PA_CPNT_USER cu1 on cu1.CPNT_TYP_ID = c.CPNT_TYP_ID and cu1.CPNT_ID = c.CPNT_ID and cu1.REV_DTE = c.REV_DTE and cu1.COL_NUM = 10
-- ITEM -> Codice Finanziamento
left outer join PA_CPNT_USER cu2 on cu2.CPNT_TYP_ID = c.CPNT_TYP_ID and cu2.CPNT_ID = c.CPNT_ID and cu2.REV_DTE = c.REV_DTE and cu2.COL_NUM = 100
-- ITEM -> Ore finanziamento
left outer join PA_CPNT_USER cu3 on cu3.CPNT_TYP_ID = c.CPNT_TYP_ID and cu3.CPNT_ID = c.CPNT_ID and cu3.REV_DTE = c.REV_DTE and cu3.COL_NUM = 90
-- Dati della Scheduled Offering
left outer join PS_SCHD_RESOURCES sr on sr.SCHD_ID = sc.SCHD_ID
-- Facility
left outer join PA_FACILITY f on f.FACILITY_ID = sc.FACILITY_ID
-- Location
left outer join PA_LOCN l on l.LOCN_ID = sr.LOCN_ID
-- Campo "Banca capofila"
left outer join PA_SCHED_USER su3 on sc.SCHD_ID = su3.SCHD_ID and su3.COL_NUM = 10
left outer join PA_USRRF_SCHED su3ref on su3ref.COL_NUM = su3.COL_NUM and su3ref.USER_ID = su3.USER_VALUE
-- Campo "Multisocietario"
left outer join PA_SCHED_USER su2 on sc.SCHD_ID = su2.SCHD_ID and su2.COL_NUM = 30
-- Campo "Codice Finanz. SKOFF"
left outer join PA_SCHED_USER su4 on sc.SCHD_ID = su4.SCHD_ID and su4.COL_NUM = 99
) q1
Which is the best way to do it?
The dbms IS birt
I temp table on a query will work?
Thanks
I have to convert it to Linq in vb.net. I am new to sql to linq. Guidance welcomed
select CONVERT(VARCHAR(10),a.StartDt,112) datenew,
COUNT(distinct(b.EmployerAccountOid)) companymoved,
COUNT(distinct(c.EmployerAccountOid)) companyfailed,
COUNT(distinct(d.ProductAccountOid)) planmoved,
COUNT(distinct(e.ProductAccountOid)) planfailed
from ebp.MgnCOREDCDataGroupMigrationRun a
left join ebp.MgnCOREDCMigrationRun b
on a.MigrationRunID = b.MigrationRunID
And TypeCd = 1 and a.MigrationStatusCd = 4
left join ebp.MgnCOREDCMigrationRun c
on a.MigrationRunID = c.MigrationRunID
and TypeCd = 1 and a.MigrationStatusCd = 5
left join ebp.MgnCOREDCMigrationRun d
on a.MigrationRunID = d.MigrationRunID
and TypeCd = 2 and a.MigrationStatusCd = 4
left join ebp.MgnCOREDCMigrationRun e
on a.MigrationRunID = e.MigrationRunID
and TypeCd = 2 and a.MigrationStatusCd = 5
group by CONVERT(VARCHAR(10),a.StartDt,112)
I tried to convert it to Linq with fail.
Dim query1= (From migrationgroup In UnitOfWork.DbContext.Set( Of MgnCOREDCDataGroupMigrationRun)()
Group Join migration In UnitOfWork.Set(of MgnCOREDCMigrationRun)() On migrationgroup.MigrationRunID Equals migration.MigrationRunID And migrationgroup.TypeCode = 1 And migrationgroup.MigrationStatusCode=4 _
Into migrationErrorGrp = Group
From mgeg In migrationErrorGrp.DefaultIfEmpty()
Group Join migration1 In UnitOfWork.Set(of MgnCOREDCMigrationRun)() On migration1.MigrationRunID Equals migrationgroup.MigrationRunID And migrationgroup.TypeCode = 1 And migrationgroup.MigrationStatusCode=4 _
Into migrationErrorGrp1 = Group
From mgeg1 In migrationErrorGrp1.DefaultIfEmpty()
Group Join migration2 In UnitOfWork.Set(of MgnCOREDCMigrationRun)() On migration2.MigrationRunID Equals migrationgroup.MigrationRunID And migrationgroup.TypeCode = 2 And migrationgroup.MigrationStatusCode=5 _
Into migrationErrorGrp2 = Group
From mgeg2 In migrationErrorGrp2.DefaultIfEmpty()
Group Join migration3 In UnitOfWork.Set(of MgnCOREDCMigrationRun)() On migration3.MigrationRunID Equals migrationgroup.MigrationRunID And migrationgroup.TypeCode = 2 And migrationgroup.MigrationStatusCode=5 _
Into migrationErrorGrp3 = Group
From mgeg3 In migrationErrorGrp3.DefaultIfEmpty()
Group By CONVERT(VARCHAR(10),migrationgroup.StartDt,112) into g
select New With{CONVERT(VARCHAR(10),migrationgroup.StartDt,112),
Count(distinct(migration.EmployerAccountOid)) ,
Count(distinct(migration1.EmployerAccountOid)),
Count(distinct(migration2.EmployerAccountOid)),
Count(distinct(migration3.EmployerAccountOid))}).ToList()
If IsNothing(query1) Then
Return Nothing
End If
coredcmigrationhistory =
From coredcmigrationrow In query1()
My query is non-queryable. Can anybody guide me where I m goin wrong