ADO.NET :: HQL (Join With Sub Query Together )
Oct 26, 2010
i am working with HQL in Nhibernate (in a C#.net Application )
i tried to implement this query
select distinct Course_Title from Course_Info join CMM_BatchCourse_Map on Fk_Course_Id= Course_Id where Fk_Batch_Id= (select Batch_Id
from CMM_Batch_Info where Batch_Title = 'BSC P1')
(THIS query is correctly in SQL SERVER )
but i tried to implement this in through HQL it gives semantic error
public IList<Course> GetByBatchName(string batchTitle)
{
ICriteria criteria = Session.CreateCriteria<Course>();
Session.CreateQuery("select distinct CourseTitle from Course join CMM_BatchCourse_Map on FkCourseId = CourseId where
Fk_Batch_Id= (select Batch_Id from CMM_Batch_Info where Batch_Title = 'BSC P1')" );
return criteria.List<Course>();
}
HOW TO WRITE THIS QUERY IN HQL ?
View 1 Replies
Similar Messages:
Feb 18, 2010
To write a join query with or condition. It means a query has two inner join, here it is possible to fetch the records, if one inner join is true and other is false. I got a record when only two join conditions are true.
View 1 Replies
Nov 18, 2010
The following query uses join operation, i want the same query to execute without using join operation. Is it possible to do so? If yes than how can i do it?select jname, jcode from heardt inner join judge ON heardt.jud1 = jcodThe reason i am trying to do this is because i am using odbc connection for mysql and join operations are not getting executed at all as web page is loading for infinitely long and not giving any output. That is the reason why i want to try without using join operation
View 7 Replies
Jul 22, 2010
i need one sql query for join two numbers...example:
a=15
b=45
c=a+b that answer i need 1545.. not 60...i dont about that query..
View 2 Replies
Dec 22, 2010
I have a problem with a sql server query, what am I missing - why doesn't it work? This is what I want to retrieve:
tblMeetings: ID, subject, description
tblOccasion: dateStart, dateStop
WHERE Meetings.status = 'bokad'
AND Meeting.ID = Occasion.meetingID
Below is two alternatives for the same result, with different error messages:
[Code]....
[dbo].[Meetings](
View 3 Replies
Aug 18, 2010
I ned to run a query with two joins, the second join does not work please help with the correct syntax.
[Code]....
View 2 Replies
Mar 15, 2011
I have this code:
public ActionResult Index()
{
MembershipUser currentUser = Membership.GetUser();
[code]...
View 3 Replies
Jun 30, 2010
i have two queries they are:
query1:
select CustID,NoOfChits from tblCust1 where [Group]='A' and CustID='a001'
query2:
select count(TKCustID) as Taken from tblAuctionGroup where [Group]='A' and TKCustID='a001'
Results of 1st query was:
----------
CustID NoOfChits
a001 2
Results of 2nd query was:
----------
Taken
4
But i want to like below:
--------------------------
CustID NoOfChits Taken
a001 2 4
in the above queries, 1st query displayed two columns and 2nd query displayed one column. but i would like to append the both results in single table or single record, i mean all results should be in same row in same result.
View 3 Replies
Jan 9, 2011
We have two related tables (inventory, inventoryLocalization) and a t-sql query works on them as follows..
select inv.[code],
coalesce(inL.name, inL2.name) as [name],
coalesce(inL.description, inL2.description) as [description]
from dbo.[inventory] inv
left join dbo.[inventoryLocalization] inL on inv.code = inL.code and inL.language = 'de'
left join dbo.[inventoryLocalization] inL2 on inv.code = inL2.code and inL2.language = 'en'
where inv.[code] like '15.' + '%'
order by inv.[code];
to performance improvement, we will try to use these tables from cache not from RDBMS directly.
for an asp.net 4.0 project, by c#. We've took both tables to chache with a DataSet and we can reach both of them through that DataSet.
DataSet ds = UtilityCache.getCachedDataSet();
"ds.Tables[0]" is inventory Table and "ds.Tables[1]" is inventoryLocalization Table
But how can we convert above T-Sql syntax to linq2Sql. is it possible to use coalesce for select statement and to join on two tables with multiple conditions ?
View 1 Replies
Jan 27, 2010
i have a form that my i use to look up whether or not there is an email address in the database. i wrote a query with this basic structure:
select *
from table A, table B
where table A.email = "email" or table b = "email"
i though that would return all instances that the email occurred in either table. what i am getting back is a bunch of null or other unrelated records from table A with a matching email in table B. the thing is, these two tables primary key to join them. i thought i wouldnt need to do that though in this case.
here is the actually query i am using if it makes things more clear:
select lm.cemailaddr, lm.b1emailadd, b.emailaddr
View 4 Replies
Mar 18, 2011
I have this code in my controller:
public ActionResult Index()
{
MembershipUser currentUser = Membership.GetUser();
Guid UserId = (Guid)currentUser.ProviderUserKey;
using (var db = new MatchGamingEntities())
{
var MyAccount = from m in db.Accounts..........
I want to be able to do a join query between my two tables Accounts and BankTransactions. This is a one to many relationship, there can be multiple BankTransactions per Account. I want to query this and display the account information including all the bank statements that are associated with it. I did a join in order to get it, but I am having trouble handling the model. I keep getting this error:
LINQ to Entities does not recognize the method 'System.Collections.Generic.List1[MatchGaming.Models.BankTransaction] ToList[BankTransaction](System.Collections.Generic.IEnumerable1[MatchGaming.Models.BankTransaction])' method, and this method cannot be translated into a store expression.
View 2 Replies
Feb 15, 2010
I know I'm missing something here but I can't figure out what it is. I've got a query joining three tables....accounts, payments, and a table linking the two (there is a M:M relationship).I'm trying to pull a list of all accounts in the account table that have a payment that needs to be resequenced, and also the maximum payment priority if there are any payments that haven't been fully paid. If all payments HAVE been fully paid, I want to return a 0.
It's that last bit of logic that I can't get right. If I include that in the where clause, I get only the accounts that have a payment that hasn't been fully paid. If I take it out, I get all the accounts I get, but I get the highest payment priority whether or not the payment has been fully met.
Here is the query....how do I include the where clause criteria but still include all accounts?
select distinct
bat.acct_id,
isnull(max(isnull(crt.pymt_priority, 0)), 0)[code].....
View 6 Replies
Apr 8, 2010
[Code]....
Well I'm not familiar with SP's yet, and I can't find a single example of what I want to do. basically I want to retrieve the town & county where the customers id are equal (note there will only ever be 1 result)
I can't figure out how to address the results to be stored within the output variables.
View 2 Replies
Mar 24, 2011
I'm trying to build a linq2Entity/gridview function for a forum, that draws data from multible tables.The result should be: Get the latest 10 threads that user(xx) has replyed in, that is not disabled or has a subject that is not allowed.Include information on the last post, thread owner user, and last post user, in each thread.
ere is my code... is returns the correct threads and some that should not be there.
[Code]....
View 1 Replies
Jan 31, 2011
I have some text files I need to parse in order to display my data, and what I have now are two text files with lots of redundant data. Instead of this I would like to replace the redundant data with a number referencing the text in another text file.
View 1 Replies
May 25, 2010
For context: First of all, I am new to LINQ, as I have been using SubSonic for quite some time now.
I have two tables, Users, and Affiliates. They both have a very typical schema. The FK that joins them is the UserId field, which is in the Affiliates table. I want to create a LINQ query that pulls the Username from the Users table using the AffiliateId value. The AffiliateId is a primary key of the Affiliates table.
I have tried to accomplish this using many variations of the following code:
[Code]....
In the above query, I expect to get a single row result set. However, I instead receive the entire table of results.
How can I make this work? I have yet to see an example or article out there to do what I am trying to do.
View 9 Replies
Sep 8, 2010
i need join 3 tables using inner join...
View 6 Replies
Mar 24, 2011
Im trying to retrieve a path name from my Pictures table the pathname is stored under picturepath in my Pictures table I dont know how to join it on to my current sql syntax it uses the UserID which is set by a session.
And im unsure what goes in the commented line for my image url string?
using (OdbcCommand cmd = new OdbcCommand("SELECT Wallpostings FROM WallPosting WHERE UserID=" + userId + " ORDER BY idWallPosting DESC", cn))
{
using (OdbcDataReader reader = cmd.ExecuteReader())
{
test1.Controls.Clear();
while (reader.Read())
{
System.Web.UI.HtmlControls.HtmlGenericControl div = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
div.Attributes["class"] = "test";
//div.Style["float"] = "left";
div.ID = "test";
Image img = new Image();
img.ImageUrl = String.Format("{unsure}", reader.GetString(unsure));
// this line needs to be represented in sql syntax
img.AlternateText = "Test image";
div.Controls.Add(img);
div.Controls.Add(ParseControl(String.Format("{0}", reader.GetString(0))));
div.Style["clear"] = "both";
test1.Controls.Add(div);
View 1 Replies
Jun 29, 2010
[Code]....
i already can't view with select new{} tags but i continued to try.
when i adding a new view, i selected PLAYER table then i wrote this code to view:
[Code]....
i guess i can do this with "sql view" but i can't create view tables for everything.
View 5 Replies
Sep 27, 2010
I have 2 datatables and i would like to join these two tables based on same TemplateID in both the tables. How can i do it in c#.
View 3 Replies
Jan 28, 2013
I have multiple tables joined using inner join to the main table but one of the field in the main table details has a field ( languages )having data as (3,7,8) ... I need to display the corresponding language
select l.LANGuage from M_Language l where l.LID in(SELECT LANGUAGES FROM details WHERE memberid='000005' )
View 1 Replies
Jun 23, 2010
if you have two table inner join like SELECT* From A INNER JOIN B on A.ID = B.IDSay A and B tables both have Username values but A's username is Test, and B's username is Test2When I do Eval("Username") it always print out "Test", how can I configure it to print out "Test2"... meaning how to specify which table's value to put using eval.. is there something like Eval(B.("Username"))??
View 6 Replies
Jan 24, 2011
I need to make a category filter. For this purpose I have two tables "Ingredient" and "Category"
My Category Table looks like this:
[Code]....
And my ingredient table:
[Code]....
I want to join the two tables so when the KategoriID match it should then return all from that category.
[Code]....
[Code]....
View 2 Replies
Sep 9, 2010
I was trying to find out how I can join more than 2 tables using the LINQ-to-SQL syntax. For instance, joining 2 tables in SQL:
SELECT * FROM Table1 AS T1 INNER JOIN Table2 AS T2 ON T1.Key=T2.Column1WHERE T2.Key='17';
can be expressed as:
var Result = from T1 in DbContext.Table1 join T2 in DbContext.Table2 on T1.Key equals T2.ForeignKey where T2.Key=17 select new { T1, T2 };
But how would I join 3 or more tables using LINQ? For example:
SELECT * FROM (Table1 AS T1 INNER JOIN Table2 AS T2 ON T1.Key=T2.Column1) INNER JOIN Table3 AS T3 ON T3.Key=T2.Column2 WHERE T2.Key='37';
I've been searching and experimenting and I cannot seem to find any informraiton on this. One example I found involves putting the result for the frist join into a temp object, and then performing the second join. I'm not sure performance-wise if that's the same as doing a 3-table join directly using a single SQL statement.
View 4 Replies
Nov 23, 2010
I have a scenario, I will pass a StatusID , According to that StatusID , The rows will be fetched from a table[tblEventStatus] and newly fetched row has to fecth the data from another table [tblEvent].
Ex: StatusID - Value I am Passing
Table 1: tblEventStatus - Column:SysID - StatusId - EventID
Table 2: tblEvent - Column:SysID - EventID - EventDesc
I want to use the Linq - I tried like this, But It doesnt work
var query1 = from objtblEventStatus in db.tblEventStatus
where objtblEventStatus.StatusId== StatusId
join objev_events in db.tblEvent on objtblEventStatus.EventID equals
(objev_events == null ? null : objev_events.UID)
select new { Category = objev_events.EventID , Name = objev_events.EventDesc};
View 1 Replies