I got the error: ORA-00933: SQL command not properly ended when run the follow linq query at LinqPad V4.42.14(AnyCPU), database is Oracle 11g.
If I replace
where coof.CoofCode == tod.PatTrnsplntFail.CoofCode && coof.OrgCode == prod.OrgCode
to
where coof.CoofCode == tod.PatTrnsplntFail.CoofCode
it works, but I can not remove that factor.
Any body can help me out will be great appreciate.
void Main()
{
var q = (from pat in Pats
from patr in pat.PatRegisters
from prod in patr.PatRegisterOrgDets
from tod in prod.TransplantOrgDets
select new {
PatId = pat.PatID,
FullName = pat.FirstName + ", " + pat.LastName,
RegisterDate = patr.RegDate.ToString("yyyy-MMM-dd"),
TransplantDate = tod.Transplant.TransplantDate.ToString("yyyy-MMM-dd"),
OrganSpec = tod.OrgSpec.Descrip,
IsTransplantedFailed = tod.PatTrnsplntFail.TodID == 0 ? false: true,
TransplantedFailReason = from coof in CausesOfOrgFail
where coof.CoofCode == tod.PatTrnsplntFail.CoofCode && coof.OrgCode == prod.OrgCode
select coof.Descrip
}).Distinct().OrderBy(o => o.PatId);
q.Dump(true);
}
I found a work around way to avoid the issue, but acturally I do not think this is a good way, I fell the LinqPad Oracle Driver has internal bugs cause that issue. Joeseph if you could read this, please give your suggestion. So use the follow linq query instead:
void Main()
{
var q1 = (from pat in Pats
from patr in pat.PatRegisters
from prod in patr.PatRegisterOrgDets
from tod in prod.TransplantOrgDets
where tod.PatTrnsplntFail.TodID == null
select new {
PatId = pat.PatID,
FullName = pat.FirstName + ", " + pat.LastName,
RegisterDate = patr.RegDate.ToString("yyyy-MMM-dd"),
TransplantDate = tod.Transplant.TransplantDate.ToString("yyyy-MMM-dd"),
OrganSpec = tod.OrgSpec.Descrip,
IsTransplantedFailed = false,
CausesOfOrgFailReason = ""
}).Distinct().OrderBy(o => o.PatId);
var q2 = (from pat in Pats
from patr in pat.PatRegisters
from prod in patr.PatRegisterOrgDets
from tod in prod.TransplantOrgDets
from coof in CausesOfOrgFail where coof.CoofCode == tod.PatTrnsplntFail.CoofCode && coof.OrgCode == prod.OrgCode
where tod.PatTrnsplntFail.TodID != null
select new {
PatId = pat.PatID,
FullName = pat.FirstName + ", " + pat.LastName,
RegisterDate = patr.RegDate.ToString("yyyy-MMM-dd"),
TransplantDate = tod.Transplant.TransplantDate.ToString("yyyy-MMM-dd"),
OrganSpec = tod.OrgSpec.Descrip,
IsTransplantedFailed = true,
CausesOfOrgFailReason = coof.Descrip
}).Distinct().OrderBy(o => o.PatId);
q1.ToList().Union(q2.ToList()).OrderBy(o => o.PatId).Dump(true);
}
Related
I have an Filter to an Array.
filter(typ: string) {
console.log("Filter");
this.nagelplattenFiltered == null;
this.nagelplattenFiltered = this.nagelplatten.filter((nagel: Nagelplatten) => nagel.Bezeichnung1 === typ);
this.nagelplatten = this.nagelplattenFiltered;
console.log(JSON.stringify(this.nagelplattenFiltered));
console.log("new: " + JSON.stringify(this.nagelplattenFiltered));
}
So we can I make a Like 'var%' we in SQL?
No you cannot. This operator doesn't exist in JavaScript. But you can use the indexOf()-method which has, used in the right way, a similar effect.
filter(typ: string) {
console.log("Filter");
this.nagelplattenFiltered == null;
this.nagelplattenFiltered = this.nagelplatten.filter((nagel: Nagelplatten) =>
nagel.Bezeichnung1.indexOf(typ) > -1);
this.nagelplatten = this.nagelplattenFiltered;
console.log(JSON.stringify(this.nagelplattenFiltered));
console.log("new: " + JSON.stringify(this.nagelplattenFiltered));
}
Your filter now delivers all Nagel-objects that contain the type-string.
I want do below query in Entity Framework
select
cast(p_min as varchar) + '' + cast(p_max as varchar)
from
user_behave_fact
where
beef_dairy_stat = 'True' and param_id = 2
group by
p_min,p_max
go
Since you have not mentioned a language, I am writing code in C#.
Try this:
using (var dbContext = new DatabaseContext())
{
var output = (
from fact in dbContext.user_behave_facts
where fact.beef_dairy_stat == "True" && fact.param_id == 2
group fact by new {fact.p_min, fact.p_max} in grp
select new
{
ColName = grp.Key.p_min.ToString() + " " + grp.Key.p_max.ToString()
}
).ToList();
}
.ToList() can be changed according to your expectations
#set($a = 10)
#set($b = 123)
#set($c = 456)
// If query string "q1" is not available then set $q1,$q2 to default values
#if($!input.params('q1') && $input.params('q1').empty)
#set($q1 = $b)
#set($q2 = $c)
// If query string "q1" available but not "q2" then add some value to $q1 and set it as $q2
#elseif($!input.params('q2') && $input.params('q2').empty)
#set($q1 = $input.params('q1'))
#set($q2 = $a + $q1 )
// If both query strings available then set them
#else
#set($q1 = $input.params('q1'))
#set($q2 = $input.params('q2'))
#end
I'm triying the above code in Integration request body mapping template. In second case where only q1 is specified as some number (let's say 10) then $q2 should be 22( 12 + 10) but it's becoming as 1210, I assume this is because those $q1 and $q2 are strings and they are getting combined.
So I tried to cast them using this answer, but I'm getting internal server error.
How can I cast string to int and them as integers?
The solution given in the other question works for me. Try this (just the second part of if-else):
#set($a = 10)
#set($q1 = $input.params('q1'))
#set($Integer = 0)
#set($q2 = $Integer.parseInt($q1) + $a)
{
"params" : {
"a" : "$a",
"q1" : "$q1",
"q2" : "$q2"
}
}
I have this code written so far and it works for what I am doing but if I search for June 13 it will only look up until June 12, can someone help me figure whats wrong in my code? or where I can add a day interval? I tried and its just not working for me.
var db = Database.Open("RMS") ;
var selectCommand = "SELECT * FROM RMS";
var formSSO = "";
var fromDate= "";
var toDate= "";
formSSO = Request.QueryString["formSSO"];
fromDate = Request.QueryString["fromDate"];
toDate = Request.QueryString["toDate"];
selectCommand = "(SELECT * from RMS WHERE SSO LIKE #0)";
if(!Request.QueryString["fromDate"].IsEmpty() ) {
selectCommand = "SELECT * FROM RMS WHERE SSO LIKE #0 AND Created BETWEEN #1 AND #2";
}
if(Request.QueryString["formSSO"].IsEmpty() ) {
<div class="simple"><strong>*SSO ID is Required.</strong></div>
}
var data = db.Query(selectCommand, formSSO, fromDate, toDate);
var columns = new[]{"ID", "SSO", "Category", "System", "Subject", "Created"};
var grid = new WebGrid(data, ajaxUpdateContainerId: "grid", defaultSort: "ID", columnNames: columns);
if (Request.QueryString[grid.SortDirectionFieldName].IsEmpty()) {
grid.SortDirection = SortDirection.Descending;
}
}
One thing you can try is using <= and >= instead of BETWEEN like this:
selectCommand = "SELECT * FROM RMS WHERE SSO LIKE #0 AND Created >= #1 AND Created <= #2";
I hope that does the trick!
If not you can also brute force the to date to be one day further into the future and then use the BETWEEN operator just you are now like this:
DateTime to_date = Convert.ToDateTime(to_date_string);
to_date = to_date.AddDays(1);
to_date_string = to_date.ToString();
I am trying to figure out how to best query in NHibernate so that the returned results are between for entries where todays time is >= PublishDateTime and <=ExpiryDateTime
The expiry date can be null so I need to allow for that. I found a couple of examples here and here but they seem to work in a different way and accept 2 values and compare to one DB field. I want the other way wrong really.
Query so far:
var query = _session.CreateCriteria<Message>()
.AddOrder(Order.Desc("PublishedDateTime"))
.List<Message>();
return query;
Any suggestions would be greatly received!
Easiest Linq query:
return _session.Query<Message>()
.Where(m => DateTime.Today >= m.PublishDateTime &&
(m.ExpiryDateTime == null ||
DateTime.Now <= m.ExpiryDateTime)
.OrderByDescending(m => m.PublishDateTime)
.ToList();
Criteria:
return _session.CreateCriteria<Message>()
.Add(Restrictions.Le("PublishedDateTime", DateTime.Today) &
(Restrictions.IsNull("ExpiryDateTime") |
Restrictions.Ge("ExpiryDateTime",
DateTime.Now)))
.AddOrder(Order.Desc("PublishedDateTime"))
.List<Message>();
In c# :
var formato = "dd/MM/yyyy h:mm:ss";
var sDesde = DateTime.Now.ToString("dd/MM/yyyy") + " 0:00:00";
var sHasta = DateTime.Now.ToString("dd/MM/yyyy h:mm:ss");
Viaje vDesde = new Viaje { Viajefecha = DateTime.ParseExact(sDesde, formato , null) };
Viaje vHasta = new Viaje { Viajefecha = DateTime.ParseExact(sHasta, formato, null) };
StringWriter strWriter = new StringWriter();
var resultado = cp.sesion.CreateCriteria<Viaje>().Add(Expression.Between("Viajefecha", vDesde.Viajefecha, vHasta.Viajefecha)).AddOrder(Order.Asc("Viajefecha")).List<Viaje>();