.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Post New Web Links

Left join Problem?

Posted By:      Posted Date: December 04, 2010    Points: 0   Category :ASP.Net
 

Dear all.......

Problem is this................

Table 1:   studentprofile

 

Rollno                 studentname             scholarid         class              section   

   1                               A                              1                 VI                   K

   2                                B                &nbs


View Complete Post


More Related Resource Links

Ms sql server left join problem

  

Hi, i have 2 tables(prduction and transact) that contain data for transactional updates per product, stock is calculated by doing sum() on one column in each table that contains the weight and to get the result per product i use group by product. My problem is that if than one value exists in the transact table, the sum(production.plannedtonnage) result is doubled for every record in the transact table. How can i fix this, any help would be greatly appreciated!

select distinct production.product

problem with inner join

  
Hi, I'm trying to create an sql query with multiple inner joins, but I can't manage this. I have 3 tables (bookings, accountplan, costs), where the data come from. In accountplan are hold the accounts, in costs the cost codes and their names, in bookings the booked events. Based on a booking event, I need the account name, the name of the cost code and all data from bookings (I need the cred account name too, but I can't figure out yet, how I can get this) I tried this: "SELECT bookings.*, accountplan.accountname, costs.costname FROM bookings INNER JOIN accountplan ON bookings.debaccount=accountplan.account INNER JOIN costs ON bookings.costcode=costs.costcode" It is here a where clause too, but I tested it, it's ok. The above query results no rows. If I remove the costs table and the inner join with it, it works. What am I missing?

Left Outer Join fails to return all records

  
I have a table tblDrop that contains 1067 records for 8/31/2010 and a table tblSoftcount that has 739 records, some with bad serial numbers. I need to match all of the records in tblDrop with those in tblSoftcount. I have a query using Left outer join that has worked for the duration of the application, but has recently stopped returing the full set of records from tblDrop. We have not changed the SQL versions on the server (compatibility level 2005). Here is the query: SELECT   v.SlotNum_ID, s.SlotNum_ID, v.PTNumber, s.PTNumber, v.DropBillAmount AS [Drop], v.ReportDate, v.DateValue     FROM tbl_Drop v LEFT OUTER JOIN tblSoftCount s ON v.SlotNum_ID = s.SlotNum_ID AND v.ReportDate = s.ReportDate WHERE   s.ReportDate = '8/31/2010' AND v.DropBillAmount <> 0 AND s.Slotnum_ID IS NULL;  

Problem with Merge Join and condition splt trasnformations in SSIS 2008

  
  Hey, While working SSIS in 2008 we have encountering some weird problems with Merge, Merge Join and Condition Spilt transformations, here are the details... Condition Split and Merge Join and Condition Split: Please check the below diagram(not really just tried) for the complete details. Just FYI data is in sorted order   condition Split -> 420000      | 18                                                          | 419982  Merge Join(left)  -- src1(6000)      |10  Condition Split      |9     |1   the merge join transformation is not returning the complete 18 rows to the next transformation that's why we are missing 8 rows. But if we adds a sort transformation (getting warning as data is already sorted) before merge then complete 18 rows were passing to the condition split. Also tried modifing the source query just to return 18 rows then also it was passing the 18 rows to next trasnformation except with full load.       Merge: We have two sorted data sources and first one has 40000 records and second source have 12000 records and after the Merge transformation we have Condition Split transfor

LINQ left outer join question

  
I can do this in other ways, but am looking for the "LINQ" way of doing this: Table1: People (PersonId,SchoolId)Table2: AssignedPeople (PersonId,SchoolId,RoomId) I want to select the people in Table1 within a particular SchoolId that are not in the assignedPeople table (in a particular Room).  The SQL is: select p.* from people p left outer join assignedpeople ap on p.PersonId=ap.Person and p.SchoolId=ap.SchoolIdand ap.RoomId=@roomId where p.SchoolId=@SchoolId and ap.PersonId is null I tried this LINQ (VB,NET):dim SchoolID as guid=...dim RoomID as guid=... (from p in dc.people where p.SchoolId=SchoolIdgroup join ap in dc.AssignedPeopleon p.PersonId equals ap.PersonId and p.SchoolId equals ap.SchoolId into groupfrom g in group.DefaultIfEmptywhere g.RoomID = nothing) but I can't get the ap.RoomId=@roomId part into the right place, should be something like:group join (from ap in dc.AssignedPeople where ap.RoomId=RoomId) Any help would be appreciated,Reuven

Left Outer Join in LINQ + Entities

  
HiI have found quite a bit of info on the net, but I can't get it to work. Here's the normal SQL query:SELECT cl.ID AS ClientID, cl.Name, cl.Surname, CLC1.PHONECODE + ' ' + CLC1.PHONENUMBER AS WorkNum, CLC2.PHONECODE + ' ' + CLC2.PHONENUMBER AS HomeNum, CLC3.PHONECODE + ' ' + CLC3.PHONENUMBER AS CellNum, CLC1.PREFERRED AS WorkNumPref, CLC2.PREFERRED AS HomeNumPref, CLC3.PREFERRED AS CellNumPref, veh.ID AS VehicleID, veh.MAKE, veh.MODEL, veh.YEAR, veh.REGNO, ws.ID AS WorkshopID, ws.JOBTYPE, ws.SERVICEADVISOR, ws.TIMEFINISHED, ws.TECHNICIAN, fs.ID as FollowupID, fs.TYPE, fs.DESCRIPTION, fs.SCHEDULEDATE, fs.WRONGNUMBERFLAG FROM CLIENTS AS cl LEFT OUTER JOIN CLIENTCONTACTNUMBERS AS CLC1 ON cl.ID = CLC1.CLIENTID AND CLC1.TYPE = 'W' LEFT OUTER JOIN CLIENTCONTACTNUMBERS AS CLC2 ON cl.ID = CLC2.CLIENTID AND CLC2.TYPE = 'H' LEFT OUTER JOIN CLIENTCONTACTNUMBERS AS CLC3 ON cl.ID = CLC3.CLIENTID AND CLC3.TYPE = 'C' INNER JOIN CLIENTVEHICLES AS clveh ON cl.ID = clveh.CLIENTID INNER JOIN VEHICLES AS veh ON clveh.VEHICLEID = veh.ID INNER JOIN WSBOOKINGS AS ws ON clveh.ID = ws.CLIENTVEHICLEID INNER JOIN FOLLOWUPSCHEDULE AS fs ON fs.WSBOOKINGID = ws.ID WHERE fs.ID = 2 There is a multiple join between CLIENTS and CLIENTCONTACTNUMBERS so it would return a single row of data. If you were to do a normal join on CLIENTS and C

problem in join two pages with session

  
hi every body I have two web pages one for inbox messages and second for details for one message in first page I have gridview include name the sender , address the message and details message alongside with buttonfield to go  to another page to view  full message the code of gridview<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="SqlDataSource1" Width="648px" onrowcommand="GridView1_RowCommand"> <Columns> <asp:BoundField DataField="sender" HeaderText="sender" SortExpression="sender" /> <asp:BoundField DataField="address" HeaderText="address" SortExpression="address" /> <asp:BoundField DataField="details" HeaderText="details" SortExpression="details" /> <asp:ButtonField Text="More..." CommandName="Show_More" /> <asp:TemplateField ShowHeader="False"> <ItemTemplate> </ItemTemplate>

left outer join linq

  
 Hi   I try to get this exsisting linq query to use a left outer join without success, can anyone show me how its supposed to be?   Dim product = (From f In db.tbl_Formats _ Join p In db.tbl_Products On f.FormatID Equals p.FormatID Where p.NodeId = iNodeID _ Select p, f.FormatName).SingleOrDefault   The FormatID is not always present and I therefore need a left outer join on the Formats table.   Best Regards

Problem with CTE return only last 5 dates , Join on dates ?

  
Declare @todate datetime, @fromdate datetime Select @fromdate=DateAdd(dd, DateDiff(dd, 0, GetDate()), 0) ,@todate=DateAdd(dd, DateDiff(dd, 0, @fromdate) -5, 0) -- select @fromdate as Today,@todate as N'5 days Back' ;With DateSequence( Date ) as ( Select @fromdate as Date union all Select dateadd(day, -1, Date) from DateSequence where Date >= @todate ) select * from DateSequence I'm missing something i just need the CTE to return last 5 dates from current date . Does join on dates , really join on datetime ? select ds.Date,et.* from DateSequence ds left outer join emp_timings et on ds.Date=et.dt and et.id=100 Above query efficient to pick last five days records ? Thanks in advance .Rajkumar Yelugu

Joining Dimtime table by a referenced Join create a problem

  

Hello

I am trying to join a dimtime table by a refernced join to an orderlines table which is the fact.

(the referenced join was defined in the relationship matrix of the cube ).

The referenced table is the ordersheader which had no measures in it but only used a linking table between those two other.

The join from the dimtime to the ordersheader  is done by date and from ordersheader to orderlines by orderid

The problem is that in the cube browser measures are shown as they were multiplied across all dates (like the join was done in a wrong way )

I have created an sql query and the logic is working just fine when quering directly from the DB

 

What am I doing wrong


query join problem

  
I am using CTE and joining it to other tables in my query.  The issue is I am not creating my joins correctly.  I am using the CTE twice but the calues in it should only appear one time on amount based on the amount type.  attached is the code
declare @dt datetime
set @dt = getdate();



With itmlvl as (


SELECT
r.EM_ITEM_NUM
,r.DSCR
,r.RBT_TYP_ID
,rb.AMT
,rb.EFF_DT
,rb.END_DT


FROM GEPRS_DNC..T_REBATE r
JOIN GEPRS_DNC..T_REBATE_PERIOD rb 
ON rb.REBATE_ID = r.REBATE_ID

)

		


select distinct top 10000 dnc.EM_ITEM_NUM
			,dnc.amt as DNC 
			,ref.SELL_DSCR
			,pur.Amt as PUR_AMT
			,psr.AMT as PSR_AMT
			,pur.RBT_TYP_ID purRBT_TYP_ID
			,pur.DSCR purDSCR
			,psr.RBT_TYP_ID psrRBT_TYP_ID
			,psr.DSCR psrDSCR
			,dnc.EFF_DT
			,dnc.END_DT
 from geprs_dnc..T_Item_cost_approved dnc
		join reference..T_iw_em_item ref 
		on ref.em_item_num = dnc.em_item_num

		INNER JOIN itmlvl 
		ON itmlvl.em_item_num = dnc.em_item_num	
		and @dt between dnc.EFF_DT and dnc.END_DT 
	
		
		INNER JOIN itmlvl pur
		ON pur.em_item_num = dnc.em_item_num	
		and @dt between dnc.EFF_DT and dnc.END_DT 
		and pur.RBT_TYP_ID = 101
	
		INNER JOIN itmlvl psr
		ON psr.em_item_num = dnc.em_item_num	
		and @dt between dnc.EFF_DT and dnc.END_DT 
		and psr.RBT_TYP_ID = 102
		
		
		

where dnc.COST_ID =32

So for PUR and PSR there should only be one amount for the given date range ...i've

Get all data - LEFT OUTER JOIN with condition

  

Hi there

I have 2 tables related,

first = WBF_EVN_evn_event(keeps all event records),
second = WBF_EVN_ptc_participant(keeps all records related to participants)

I'm trying to get all events which the current user has not attended or not replied(if ptc_pts_id = 2 then the participant has not attended OR I want to see also where ptc_pts_id is NULL)

       SELECT                  evn_id, evn_name, evn_date_start, evn_date_end, ptc_pts_id, ptc_usr_id
       FROM                    WBF_EVN_evn_event
       LEFT OUTER JOIN         WBF_EVN_ptc_participant ON evn_id = ptc_evn_id
       WHERE                   evn_deleted = 0 
       AND                     (ptc_pts_id is NULL or (ptc_pts_id = 2 AND ptc_usr_id = 24 ) )       
       AND                     evn_dom_id = 1


With this query I get up to some point good result;if there is no other

Join Expression Not SHi All, I use Access 2007, and I have the following SQL problem: I have two t

  
Hi All,

I use Access 2007, and I have the following SQL problem:

I have two tables TransformerTypePeriodBOMProducts and TransformerTypePeriodProducts. The first table has 4 fields: TransformerTypeID, OutputProductID, PeriodID and BOM, while the second has the following 4 fields: TransformerTypeID, OutputProductID,PeriodID and AssemblyCapacity. So as you can see, there are 3 fields (TransformerTypeID, OutputProductID and PeriodID) that are in both tables.

I need to delete all records in the first table that have the field AssemblyCapacity in the second table equal to 0 (and of course have similar TransformerTypeID, OutputProductID and PeriodID fields).

I tried many trials, the last I got was:

SELECT TransformerTypeAssemblyPeriodBOMProducts.*
FROM ((TransformerTypeAssemblyPeriodBOMProducts INNER JOIN TransformerTypeAssemblyPeriodProducts ON TransformerTypeAssemblyPeriodBOMProducts.TransformerTypeID=TransformerTypeAssemb
lyPeriodProducts.TransformerTypeID) INNER JOIN TransformerTypeAssemblyPeriodProducts ON TransformerTypeAssemblyPeriodBOMProducts.OutputProductID=TransformerTypeAssembly
PeriodProducts.OutputProductID) INNER JOIN TransformerTypeAssemblyPeriodProducts ON TransformerTypeAssemblyPeriodBOMProducts .PeriodID=TransformerTypeAssemblyPeriodProducts.PeriodID
DELETE * FROM TransformerTypeAssemblyPeriodB

My problem in update inner join

  

Hi

I have a temp table CTE, with column introducerId and 3 rows as show below.  My update query should affect on 3 rows(Or  times). But it affect only on two rows because “2” is repeated twice in CTE. How can I force it to update 3 times (member.id is unique). In other word: it should update m.RoI where m.id=2, twice

update m set m.RoI = m.RoI +  dbo.udfGet_myFunc(t.CPT)

            from

Table JOIN Problem

  

I write the following queries :

select y.date, y.item,y.ingredient, (CAST(z.rate AS DECIMAL(10,4)) * CAST(y.qty AS DECIMAL(10,4))) FROM master.recipe_ingredient AS x JOIN master.ingredient as z on x.ingredient = z.item JOIN executive.consumption_Entry as p ON x.recid = p.recid JOIN executive.consumption_total_ingredient AS y ON p.cid = y.cid

and the output is:

10/09/2010    REG    MAIDA    491.37600000
10/09/2010    REG    MAIDA    1152.89800000
10/09/2010    REG    MAIDA    169.44000000
10/09/2010    REG    MAIDA    1306.10000000
10/09/2010    REG    MAIDA    3400.44900000
10/09/2010    REG    MAIDA    1742.40800000
10/09/2010    REG    MAIDA    1553.20000000
10/09/2010    REG    MAIDA    3812.40000000
10/09/2010    REG    MAIDA    1629.44800000
10/09/2010    REG    MAIDA    29652.00000000

10/09/2010    REG    SUGAR &nbs

problem with sql data source - view with INNER JOIN

  

Hello!

I have a question. I created a new data source (sql database connection) - a view that contains INNER JOIN statement. After that I created a page and put Edit Item Form on it based on this data source. When I open a page and try to update some records I get an error: "The data source control failed to execute the update command."

There is no error when I use a view without INNER JOIN...

Can I solve it? Should I write my own UPDATE statement?

Thank you.


NULL for user who don't have appointment - UNION error ... LEFT JOIN doesn't work

  

Hi,

It's so silly what i'm trying to do.. I just need to catch the entire list of user and null for users who don't have appointment ....

I tried union but I've got an error, please help

 

Msg 205, Level 16, State 1, Line 2
All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.




declare @SQL Varchar(4000)

declare @CRM_FilteredAppointment nvarchar(2000)
declare @CRM_FilteredSystemUser nvarchar(2000)



set @CRM_FilteredSystemUser = 'SELECT systemuserid, eu_reporthubname, fullname, businessunitidname 
 FROM FilteredSystemUser 
 WHERE businessunitidname = ''Spain''
'
--exec (@CRM_FilteredSystemUser)

set @CRM_FilteredAppointment = 'SELECT activityid, ownerid, regardingobjectid, subject, scheduledend 
 FROM FilteredAppointment 
'

set @SQL = ' 
 SELECT SU.systemuserid, SU.fullname, count(partyid)
 FROM (' + @CRM_FilteredSystemUser + ') AS SU
   LEFT JOIN
    (' + @CRM_FilteredAppointment + ') as Apt ON 
    SU.systemuserid = Apt.ownerid 
   INNER JOIN
    FilteredActivityParty AS AP ON Apt.activityid = AP.activityid 
   AND (AP.participationtypemask = 8 OR AP.participationtypemask = 5) 
 WHERE Partyidname is not null 
group by SU.systemuserid, SU.fullname
UNION ALL 
SELECT
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend