Advanced Join???

Aug 3, 2007

I have two tables X and Y which need to join together. Table X has an ID field which connects to an ID field in Table Y. My problem is the ID field in Table X can contain multiple ID's EX:

Table X
ID
-------
2,1,4,
2,5,
1,
3,1,2,4,
ect...
whereas the ID field in Table Y contains one ID in each row EX:

Table Y
ID Color
------- -------
1 Green
2 Blue
3 Red
4 Yellow
5 Orange
ect...

Is there a way to join these two tables together? I need the output to be...

ID Color
------ -------
2,1,4, Blue,Green,Yellow
2,5, Blue, Orange
1, Green
3,1,2,4, Red, Green, Blue, Yellow
ect...

View 8 Replies


ADVERTISEMENT

Advanced Join Question

May 12, 2008

I have a query in which I have constructed a bunch of left outer joins, however I need to also join one of the tables on the "right" side of one of those joins with an entirely different table. What I have is as follows:

select F.*, FRL.findingRiskLevel, E.entityName, G.gName, FRS.findingStatus, FCA.findingControlArea, A.aYear, A.aDesc
from Findings F

left outer join Audits A ON A.aID = F.auditID
left outer join Entities E ON E.entityID = F.findingEntity
left outer join Groups G ON G.gID = F.findingGroup
left outer join FindingsReportingStatus FRS ON FRS.findingStatusID = F.findingRepStatus
left outer join FindingsControlAreas FCA ON FCA.findingControlAreaID = F.findingControlArea
left outer join FindingsRiskLevels FRL ON FRL.findingRiskLevelID = F.findingRiskLevel

So I also need to join Audits.aTypeID on AuditTypes.aTypeID and pull back AuditTypes.aType

Any tips appreciated! My attempts thus far have failed me :)

View 3 Replies View Related

SQL Query JOIN Needed? Too Advanced For Me

Sep 5, 2006

THIS LOOKS LIKE A LOT BUT I JUST WANTED TO GIVE ALL INFORMATION NEEDED FOR YOU TO EASILY ASSIST ME.  I am not good with SQL so please bare with me. I will give a dumbed down table for us to work with:timestamp          -   DATA1 - DATA2 - MAXVALUENEEDED - DATA32006/8/12 12:00       123         125             1289                      121 2006/8/12 12:05       124         128             1291                      1232006/8/15 12:00        130        128              1190                     1242006/8/15 1:00          131        127             1196                      123  The columns labeled DATA do not really matter.  The only important ones are timestamp and MAXVALUENEEDED but I do need the query to return all columns. What the query has to do: The query needs to find the MAX of MAXVALUENEEDED for a given DAY.  Example Output- 2006/8/12      124   128   1291   1232006/8/15      131   127   1196   123As you can see the MAX values were grabbed for each given day and the unique records were returned on a per day basis. My current SQL Query is:  SELECT CONVERT(varchar, timestamp, 101) AS Time, CONVERT(int,LV50AEPM_AMPS_A_VAL0) AS AMPS_A, CONVERT(int,LV50AEPM_AMPS_B_VAL0) AS AMPS_B, CONVERT(int,LV50AEPM_AMPS_C_VAL0) AS AMPS_C,
CONVERT(int,LV50AEPM_KVA_TOT_VAL0) AS KVA_TOTAL, CONVERT(int,LV50AEPM_KW_TOT_VAL0), CONVERT(int,LV50AEPM_VLL_CA_VAL0), CONVERT(int,LV50AEPM_VLL_BC_VAL0), CONVERT(int,LV50AEPM_VLL_AB_VAL0)
FROM Table_1 T1
WHERE CONVERT(int,T1.LV50AEPM_KVA_TOT_VAL0) = (SELECT MAX(CONVERT(int,T2.LV50AEPM_KVA_TOT_VAL0)) FROM Table_1 T2 WHERE CONVERT(varchar,T1.timestamp,101) = T2.timestamp)
ORDER BY Time ASC The problem is it only returns the max value for one day instead of all days.  Can anyone help me correct this?  Thanks in advance for your help. 

View 34 Replies View Related

Can Any One Tell Me The Difference Between Cross Join, Inner Join And Outer Join In Laymans Language

Apr 30, 2008

Hello

Can any one tell me the difference between Cross Join, inner join and outer join in laymans language

by just taking examples of two tables such as Customers and Customer Addresses


Thank You

View 1 Replies View Related

I Need Advanced Help Please.

Oct 19, 2005

Here's one for one of you SQL genuises out there.  I really appreciate any help that I can get.  There are several steps to this.Step 1:I have a database that holds timesheet records for users.  These records are by week.  I need a query that will return the username of the people that have entered 0 time for all of their timesheets in the database.Step 2:I need a query that will delete and timesheets that have 0 time entered after the last timesheet with time entered.  If they entered time in week 3 but have 0 time for week 4 and 5 and then are withdrawn at week 5 I need to remove timesheets for week 4 and 5.  Note, they could have entered 0 for week 2 as long as week three has time entered.Step 3: - THIS IS THE MONSTER-Since the timesheets are by week, I need to find the date that the last time was entered.  The timesheet has a start-date then suntime, montime, tuetime, wedtime etc.  Sunday would equal the week start-date.  So, if time was last entered on Friday, the date that I'm looking for is the start-date + 5.  My problem is, How do I go about doing this?  I've been trying to do it all in a query to no avail.I really appreciate any assistance that anyone can offer.Thank you,Still learning........-Scott

View 4 Replies View Related

How To Do Advanced Sum?

Oct 18, 2007

Hi

I'm new in Reporting Services and I have a task to solve. I wonder how to do it in Reporting Services.

For example I have few records:





ID
Year
Q1
Q2
Q3
Q4

1
2005
0
0
10
20

2
2006
20
20
35
35

3
2007
40
45
45
10 Now I create two parameters:
Q and Year

When I run this report I want to choose for example Year = 2006, and Q = 3

When I choose these values I need to calculate a field in report like this:

needed_sum = 0(Q1,year=2005) + 0(Q2,year=2005) + 10(Q3,year=2005) + 20(Q4,year=2005) + 20(Q1,year=2006) + 20(Q2,year=2006) + 35(Q3,year=2006)


I need to declare variables, like it is calculating on a section in other reports systems. Here I found only code for report where I can write some functions.

Anyway..
Did someone knows how to solve this problematic task??

Regards

Bashay

View 4 Replies View Related

Integration Services :: How To Perform Left Restricted Join In Merge Join Transformation

May 22, 2015

I have two xml source and i need only left restricted data.

how can i perform left restricted join?

View 2 Replies View Related

Transact SQL :: Difference Between Inner Join And Left Outer Join In Multi-table Joins?

Oct 8, 2015

I was writing a query using both left outer join and inner join.  And the query was ....

SELECT
        S.companyname AS supplier, S.country,P.productid, P.productname, P.unitprice,C.categoryname
FROM
        Production.Suppliers AS S LEFT OUTER JOIN
        (Production.Products AS P
         INNER JOIN Production.Categories AS C

[code]....

However ,the result that i got was correct.But when i did  the same query using the left outer join in both the cases

i.e..

SELECT
        S.companyname AS supplier, S.country,P.productid, P.productname, P.unitprice,C.categoryname
FROM
        Production.Suppliers AS S LEFT OUTER JOIN
(Production.Products AS P
LEFT OUTER JOIN Production.Categories AS C
ON C.categoryid = P.categoryid)
ON
S.supplierid = P.supplierid
WHERE
S.country = N'Japan';

The result i got was same,i.e

supplier     country    productid    productname     unitprice    categorynameSupplier QOVFD     Japan     9     Product AOZBW    97.00     Meat/PoultrySupplier QOVFD    Japan   10     Product YHXGE     31.00     SeafoodSupplier QOVFD     Japan   74     Product BKAZJ    10.00     ProduceSupplier QWUSF     Japan    13     Product POXFU     6.00     SeafoodSupplier QWUSF     Japan     14     Product PWCJB     23.25     ProduceSupplier QWUSF    Japan     15    Product KSZOI     15.50    CondimentsSupplier XYZ     Japan     NULL     NULL     NULL     NULLSupplier XYZ     Japan     NULL     NULL     NULL     NULL

and this time also i got the same result.My question is that is there any specific reason to use inner join when join the third table and not the left outer join.

View 5 Replies View Related

Warning - The Join Order Has Been Enforced Because A Local Join Hint Is Used

Dec 23, 2014

I have two select statements, in between select statement taking UNION ALL . I need to avoid the error

Warning: The join order has been enforced because a local join hint is used.

View 9 Replies View Related

'Left Outer Merge Join' Failing To Join Valid Row

Aug 10, 2007

Scenario:

OLEDB source 1
SELECT ...
,[MANUAL DCD ID] <-- this column set to sort order = 1
...
FROM [dbo].[XLSDCI] ORDER BY [MANUAL DCD ID] ASC


OLEDB source 2
SELECT ...
,[Bo Tkt Num] <-- this column set to sort order = 1
...
FROM ....[dbo].[FFFenics] ORDER BY [Bo Tkt Num] ASC

These two tasks are followed immediately by a MERGE JOIN

All columns in source1 are ticked, all column in source2 are ticked, join key is shown above.
join type is left outer join (source 1 -> source 2)

result of source1 (..dcd column)
...
4-400-8000119
4-400-8000120
4-400-8000121
4-400-8000122 <--row not joining
4-400-8000123
4-400-8000124
...


result of source2 (..tkt num column)
...
4-400-1000118
4-400-1000119
4-400-1000120
4-400-1000121
4-400-1000122 <--row not joining
4-400-1000123
4-400-1000124
4-400-1000125
...

All other rows are joining as expected.
Why is it failing for this one row?

View 1 Replies View Related

Advanced Search Box????

Aug 15, 2006

Hi, Using Visual Web Developer and SQL Express, (coding in Csharp) I want to add a
advanced search facility to my site. Problem is I do not know  how to begin.
The website is a business directory and displays company names and services that  they provide.
Here is where I am at....
So far I have made one query which allows users to search the database by "town" such as if they enter  "London" in the text box, it returns the relevant records into a gridview.
Rather than have a seperate text box for each query, I want to  provide an advanced search box option so users can define their search and query the database by various criterias, such as geography, sector, name, number of employees in companies etc.
I have seen compact advanced search boxes on many sites!.
Replies greatly appreciated.
prontonet
 
 
 
 

View 8 Replies View Related

SQL And ASP.NET Advanced Query

Jun 19, 2008

I want to query a database through a ASP.NET page   and I want to set the page up like an advanced search page would look.  My question is,    how do I write the stored procedure and/or what value do I pass from ASP.NET to accomplish null or blank values.    For instance, if someone wants to query by TRIP id and not vehicle ID   then how do I write the where claue? 

View 10 Replies View Related

Advanced Query

Feb 7, 2006

I have the following figured out, however what I want to do is almost come up with a new column based on if the row actually exists in the employeeeval column:
SELECT e.DeptID, e.LastName + ', ' + e.FirstName AS EmpName, e.EmployeeID, u.UserName FROM Employee e LEFT OUTER JOIN EmployeeEval ev ON e.EmployeeID = ev.EmployeeID LEFT OUTER JOIN [User] u ON u.Department = e.DeptID WHERE (u.RoleID = 'supervisor') AND (e.CompanyID = @CompanyID) AND (e.FacilityID = @FacilityID) AND (ev.PersonalScore IS NULL) ORDER BY e.DeptID, e.LastName
so in my select I want to add something like ev.approved which then that brings back either Null or 0.  Then based on that create a variable to bring back as a string and if it = 0 make my string say 'In Progress' and if it's Null, say 'Not Started'.  I would imagine I would need a Declare @Status nvarchar(15) --- but I get lost after that b/c wouldn't I need some sort of way to count throught the rows of my result set and do an IF statement? I can't quite figure this process out, after numerous attempts.

View 14 Replies View Related

Advanced Ordering

Mar 5, 2001

Hello.
I want to order a resultset from a table by two columns in another table. Here's how it looks:

[Books]
ID
Title


[linkBookAuthor]
BookID (Books.ID)
AuthorID (Authors.ID)

[Authors]
ID
Firstname
Lastname
AuthorOrder

As you can see it's a many to many relationship. Is there a way to order the books by Authors.Lastname (the first if there are several authors) with one query ? If not, what is the fastest way ? I don't need the names in the resultset so I only want to order the books by Authors.Lastname, not include Authors.Lastname.

Thanks for any help.

View 1 Replies View Related

Advanced SQL Tutorials

Nov 29, 2005

Dear All,

Can you suggest a good book or set of websites which have advanced SQL tutorials for SQL server? Got the basics but looking to build on my knowledge.

...cause knowledge is power...

View 3 Replies View Related

Advanced Queries

Mar 22, 2006

Keri writes "I am still a SQL newbe, but have learned a lot in the past year. I am not creating databases, nor maintaining our SQL Server 2000. I am a report writer and use Query Analyzer for the base of my reports. I use Actuate to develop the reports. My question is, i am interested in getting a book that covers more advanced querying. I have the book The Guru's Guide to Transact-SQL, but am intested in other books to further my growth and education in SQL. Can you suggest some books that deal with queries-advanced primarily since i really am not designing or maintaining the DB. Thanks for any information you can give.

Sincerely,
Keri Taylor"

View 4 Replies View Related

Advanced Joins

May 11, 2006

Here's a challenge for one of those database experts out there...

I want to join two tables in a Left Join format, with the first table being the one referencing the second table. Easy enough right? Well, I also want to be able to reference this second table from 3 different fields.
For example:

My tables
#1: video
id, description ...etc... award1, award2, award3

#2: award
id, description, image, etc...

As you can see, I want to be able to award more than 1 award from the "award" table to each video in the "video" table. I then want to be able to assign a variable to each field from the result of the SQL query so I can display all the information on one page for every video with every combination of possible awards.

I also, in my SQL Query, want a WHERE clause:
WHERE video.id = $vidid (a variable from a previous page so this page only displays the video I want)

My mind says surely this must be possible, but I have no idea how to go about it. Can anyone give me any hints/help/pointers/advice on this? Even if this requires two SQL queries, I may be able to work with that, but I need to know. If I'm posting at the wrong place, or nobody here knows how to do this, then I would also really appreciate being pointed in the right direction.

Thanks in advance to anyone who even reads this and thinks over it. This is for a free online fan site http://www.lostvideo.net/ that I'm helping with some redesigns.

View 2 Replies View Related

Help With More Advanced Functions

Jul 20, 2005

I have been able to get several basic databases to function both in playingaround and functional ones on the web but they have all been pretty simple.I am now trying to develop a database for the web using Access. What I amreally needing help with is how to actually reduce the number of record setsthat I think i am going to need. Here is what I am trying to do.I am having people sign up and create teams. So you come to the site and yousee Team 1, Team 2... Team 8. (These numbers will later be replaced by realnames given by the team captains and replaced in the database, this will bedone by the captain through the web)You pick a team you want to be on, enterthe info and you are placed on that team (in the database) I have two tablesin the database TeamRoster (everyone on all of the teams) and Teams (Listthe captains and the names of their team)So when I query the database to fill the tables I am confused as to how Ishould go about the query. As I see it I need to build a RS (Record Set) foreach team to get the name of the team for the appropriate table, thenpopulate it with the players for that team (repeating region) if there areeight teams, that means 16 RS. This does not seem right.Am I making any sense?Thanks for trying to understand all of this.Houston

View 1 Replies View Related

Advanced Services

Nov 7, 2007

When one requirement says that MS SQL Server 2005 with Advanced Services is required, what does it mean by "Advanced Services"? Doesn't the full version of SQL2005 include all the advanced services? What are advanced services? I've seen the Express version with Advanced Services but this is the full version I'm talking about.

Thank you all in advance.

View 5 Replies View Related

Multi-table JOIN Query With More Than One JOIN Statement

Apr 14, 2015

I'm having trouble with a multi-table JOIN statement with more than one JOIN statement.

For each order, I need to return the following: CarsID, CarModelName, MakeID, OrderDate, ProductName, Total ordered the Car Category.

The carid (primary key) and carmodelname belong to the Cars table.
The makeid and orderdate belong to the OrderDetails table.
The productname and carcategory belong to the Product table.

The number of rows returned should be the same as the number of rows in OrderDetails.

View 2 Replies View Related

Select Command - Left Join Versus Inner Join

Aug 9, 2013

Why would I use a left join instead of a inner join when the columns entered within the SELECT command determine what is displayed from the query results?

View 4 Replies View Related

Merge Join (Full Outer Join) Never Finishes.

Jun 5, 2006

I have a merge join (full outer join) task in a data flow. The left input comes from a flat file source and then a script transformation which does some custom grouping. The right input comes from an oledb source. The script transformation output is asynchronous (SynchronousInputID=0). The left input has many more rows (200,000+) than the right input (2,500). I run it from VS 2005 by right-click/execute on the data flow task. The merge join remains yellow and the task never finishes. I do see a row count above the flat file destination that reaches a certain number and seems to get stuck there. When I test with a smaller file on the left it works OK. Any suggestions?

View 3 Replies View Related

Why Does My Query Timeout Unless Force Join To Hash Join?

Jul 25, 2007

I'm using SQL Server 2005.



A piece of software I wrote starting timing out on a query that left outer joins a table to a view. Both the table and view have approximately the same number of rows (about 170000).



The table has 2 very similar columns, one is a varchar(1) and another is varchar(100). Neither are included in any index and beyond the size difference, the columns have the same properties. One of the employees here uses the varchar(1) column (called miscsearch) to tag large sets of rows to perform some action on. In this case, he had set 9000 rows miscsearch value to "g". The query then should join the table and view for all rows where miscsearch is set to g in the table. This query takes at least 20 minutes to run (I stopped it at this point).

If I remove the "where" clause and join all rows in the two tables, the query completes in about 20 seconds. If set the varchar(100) column (called descrip) to "g" for the same rows set via miscsearch, the query completes in about 20 seconds.



If I force the join type to a hash join, the query completes using miscsearch in about 30 seconds.



So, this works:

SELECT di.File_No, prevPlacements, balance,'NOT PLACED' as status FROM Info di LEFT OUTER HASH JOIN View_PP pp ON di.ram_file_no = pp.file_no WHERE miscsearch = 'g' ORDER BY balance DESC



and this works:

SELECT di.File_No, prevPlacements, balance,'NOT PLACED' as status FROM Info di LEFT OUTER JOIN View_PP pp ON di.ram_file_no = pp.file_no WHERE descrip = 'g' ORDER BY balance DESC



But this does't:

SELECT di.File_No, prevPlacements, balance,'NOT PLACED' as status FROM Info di LEFT OUTER JOIN View_PP pp ON di.ram_file_no = pp.file_no WHERE miscsearch = 'g' ORDER BY balance DESC



What should I be looking for here to understand why this is happening?



Thanks,

john















View 1 Replies View Related

Advanced SELECT For A Newbie

Oct 5, 2006

I have a table full of Latitudes, Longitudes, address, customername, etc. , I need to grab some input(Latitude, Longitude, range) from the user.  So now I have a source lat, long(user) and destination lat, long(rows in dbase).  I need to take the 2 points and compute a distance from the user given lat, long to every lat, long in the database and check that distance againt the range given from the user.  If the distance is below the range, I need to put that row into a temp table and return the temp table at the end of the stored proc.  As of right now I am completely lost and need some guidance. I would also like to be able to add the computed distance to a table.  Here is the function and stored procedure i have so far...ALTER PROCEDURE [dbo].[sp_getDistance]      @srcLat        numeric(18,6),    @srcLong    numeric(18,6),    @range        intASBEGIN    SET NOCOUNT ON;    SELECT * FROM dbo.PL_CustomerGeoCode cg    WHERE dbo.fn_computeDistance(@srcLat, cg.geocodeLat, @srcLong, cg.geocodeLong) < @rangeEND CREATE FUNCTION fn_computeDistance (    -- Add the parameters for the function here    @lat1        numeric(18,6),    @lat2        numeric(18,6),    @long1        numeric(18,6),    @long2        numeric(18,6))RETURNS numeric(18,6)ASBEGIN    -- Declare the return variable here    DECLARE @dist        numeric(18,6)    IF ((@lat1 = @lat2) AND (@long1 = @long2))        SELECT @dist = 0.0    ELSE        IF (((sin(@lat1)*sin(@lat2))+(cos(@lat1)*cos(@lat2)*cos(@long1-@long2)))) > 1.0            SELECT @dist = 3963.1*acos(1.0)        ELSE            SELECT @dist = 3963.1*acos((sin(@lat1)*sin(@lat2))+(cos(@lat1)*cos(@lat2)*cos(@long1-@long2)))    -- Return the result of the function    RETURN @dist Thanks, Kyle 

View 1 Replies View Related

Sqldatasource And Advanced Options

Mar 13, 2007

Hello, I am trying to bind a sqldatasource control to the gridview.
I have selected the sqldatasource control and specified the connection string, on configure  Select statement page under advanced options both the check marks
Generate INSERT, UPDATE and DELETE Statements
Use Optimistic Concurrency  
are disabled for me.I have a proper SQL Server database not an express data base, how do i get to generate the InserCommand, EditCommand etc
Any help would be great .. relatively new here
thanks 
 

View 2 Replies View Related

Advanced Identity Fields

Apr 19, 2007

Hi!
a) PROBLEM 1:
I have set up my main database like this (of course I'm showing an abbreviation):
company - int (identity)name - nchar
I have several companies stored in the previous table. Now I have another table with messages:
company - int (related with the company of the previous table)messageID - int (identity)contents - nchar
company and messageID are the main key of this table. I want to set the messageID column to change automatically. Since I declared it as identity it is working fine, but I was looking to start it on 0 on every new company:
Company messageID0              00              10              21              0 <- Here the company changed, so the messageID resets1              11              21              32              0 <- Again2              1
Any suggestions?
b) PROBLEM 2:I have my database stored locally on my computer. When I finished working with the database it has a lot of data for testing. I want to upload the database to my hosting provider or to my customer's. But the identity columns keep incrementing since the last value of my tests, so it's kind of annoying to see values as: 1250, 223, etc. when I expect to see 0,1, 2 and so on. Also, for receipts this is a very important issue.
How can I reset the identity fields?
Thank you very much for your attention and help.
CT

View 3 Replies View Related

Advanced SQL Generations Options

May 13, 2007

Advanced SQL generations options:
generate INSERT, UPDATE, and DELETE statements is all greyed out?
in my sql data source control.?
I have made a brand new instance with sql server management express....have I missed something?

View 4 Replies View Related

SQL Express/Advanced Performance

Jan 9, 2008

Hi There,
I know this might be slighty off topic, but (apart from the CPU, RAM & DB size limits) does anyone know if Express SQL server has any performance / concurrent connection restrictions when compared to SQL 2005 Standard?
Many thanks
Ben

View 1 Replies View Related

Advanced Stored Procedure...

May 25, 2004

Hello,

(Excuse my english, i'm a french man)

I want to make a stored procedure on that model :

CREATE Procedure SGCP_GetEleveArgs
(
@Arg1 nVarChar,
@Val1 nVarChar
)
AS
SELECT *
FROM Eleve
WHERE @Arg1 = @Val1

So you understand that i want to pass my argument (@Arg1) as a field of a column.
but it gives :

WHERE 'Nom' = 'Dupont'

but i want to have :

WHERE Nom = Dupont

for it to work.
Have you an idea to solve that problem ?

Thanx

View 5 Replies View Related

Advanced Functions In SQL Express

May 31, 2006

Hi,
I would like exploring Reporting Services associated with SQL Express Edition so i tried installing "SQLEXPR_ADV_.EXE" the package available on download SQL site, but after having selected Reporting Services option I've got an error explaining that component "sqlserver2005_bc.msi" is to be changed.
As this component is part of "SQLEXPR_ADV_.EXE" package is there anybody knowing an alternative solution ?
 

View 1 Replies View Related

SQL Query Advanced Option

Apr 18, 2001

I want to run a query overnight through the SQL agent using osql. However I need to turn off the print header option that you normally turn off through the advanced options tab in the Query Analyzer. Does anyone know if this is possible?? Many Thanks in advance..

View 1 Replies View Related

Help !!! - DTS Package - Advanced Properties

Feb 27, 2001

Has anybody used the "Use fast load" or "Table lock" options in the advanced DTS package properties ? These are supposed to be in the Advanced tab of the Data Transformation Properties dialog box. I cannot seen to find them. I want to set them in order to have the load execute in nonlogged mode. Any help would be very much appreciated.

Thanks in advance.

View 2 Replies View Related

Chart Examples - Advanced

Mar 28, 2006

Hello, Can anyone direct me to some sample charts created with 2000 Reporting Services? Looking for the advanced capabilities and quality of the charts.

Thanks
SactoJoe

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved