Join On Similar Data

Feb 23, 2015

Table One is an older database and has the column employee id, which would always consist of first letter of the last name an underscore and a numeric value. So for example, data looks like

employeeID
R_12345678
S_5555555
T_777777
U_7777

Our new data structure simply removed the letter & underscore.

employeeID
12345678
5555555
777777
7777

Now my question is, how could I join on oldDB.employeeID to newDB.employeeID since the data is very similar, but not exactly the same?

View 9 Replies


ADVERTISEMENT

Join Two Datasets From A Similar Column

Apr 23, 2008

Hi, I was wondering wich is teh easiest way to solve this:


I have one data set that comes from a sql query with many columns.

I have another data set that comes from a txt file that I am reading.

Both data set have one column in common (for example ID).

In the sql data set, I have many rows and I want to keep only the ones that have the same ID from the data set of my txt file. It looks like a inner join if we talk in sql terms.

So, which is the easiest way to solve this?
Thanks!

View 6 Replies View Related

How To Basically Copy Tables With New Names Rather Than Create Similar Tables From Similar Manual Input.

May 26, 2007

I have a table that I am basically reduplicating a couple of times for each part of this database that I want to create.Each table basically has the same data: The tables will be called motherTable, fatherTable, sonTable, daughterTable and so on.I am pretty much using the following in each column: UserID, MotherID(or FatherID or SonID, etc., etc. and so on for each unique table), FirstName, LastName, MiddleName, BirthPlace, Photo, Age.I don't see an option to copy a table and just modify the second ID part and rename that table accordingly.How can I make this an easier way of creating these similar tables without retyping all these columns over and over again?Thanks in advance. 

View 4 Replies View Related

Select Similar Data

Aug 15, 2012

finding is queries to find duplicate data.Basically I have a picklist table in a database and I have discovered that there are what looks like duplicate data (because the name is the same) but there is a different number on the end, as you can see from an example below.

NO, ENTRY
24, John Doe|26|05768
24, John Doe|26|5768

Do you know if there is a sql query that can be ran against this table that will look through the ENTRY column and select fields that are similar and not duplicates (duplicates can't exist due to PK constraints)

View 8 Replies View Related

Consolidating Data From 7 Similar Databases

Mar 15, 2007

I'm not quite sure if this is the correct forum to post this, if not please advise where should I post.



I have 7 databases with same structure, but different data in it, I need to have a query to consolidade some info from all of them in one report, is it possible just in onw script? how should I do it?



thanks,



Marcus

PS: I'm a beguinner in this so I apologize if the question seems stupid, or wrong.

View 1 Replies View Related

Design Data Storage For Feature Similar To Facebook Groups

Mar 13, 2008

Ok so facebook groups have 100,000's of members. Members can be part of an unlimited number of groups, and a group can have an unlimited number of members.

Comma Deliniated String seems absurd. Many-2-Many Database relationship seems like it won't scale well t the 10's of thousands and 100's of thousands of members (especially if you have 1000-5000 groups). A table for each group would work but thats a bit over the top in my opinion. XML file doesn't seem to be any better than the above options.

I am no database guru, but I can't figure out a scalable method of doing this, be it with or without a database. I need something that can support 10 groups that have 20 members each OR 1000 groups with 100,000 members each.

Any help, suggestions, or kicked in the right direction would be most appreciated.

View 3 Replies View Related

SQL Server 2014 :: Splitting Similar Data Into Separate Columns?

Aug 18, 2015

If you see below there are 2 customer names on 1 loan, most of them share the same lastname and address, I want to separate it with fields,LoanID, customer 1 Firstname, Customer 1 Lastname, Customer 2 FirstName, Customer 2 Lastname, Adddress,zip

Loan IDFirst NameLastnameAddressaddress 2CityStateZip
1236048Joey Yesen xxxx abc GROVE RDNULLCLEVELANDTX77327
1236048Dickey Yesen xxxx abc GROVE RDNULLCLEVELANDTX77327
1235983Randy Seany xxxx abc Haleyville StNULLAuroraCO80018
1235983Barry Seanyxxxx abc Haleyville StNULLAuroraCO80018

The query I am using

select
L.Loanid
,B.FirstMiddleName
,B.LastName
,MA.AddressLine1
,MA.AddressLine2
,MA.City
,MA.State
,MA.Zip

from Loan AS L

LEFT JOIN Status As S on S.LoanID = L.LoanID
LEFT JOIN Borrower B on B.LoanID = L.LoanID
LEFT JOIN MailingAddress MA on MA.LoanID = L.LoanID
where S.PrimStat = '1' and B.Deceased = '0'

View 3 Replies View Related

How Do I Copy Data From Similar Tables Knowing Unique ID Fields

Jul 20, 2005

I have two tables in my database called CartItems and OrderItems. Istore all of a session's shopping cart items in the CartItems tableusing the sessionID as the identifier (called cartID in my DB). Afteran order is placed and is approved, I would like to copy all of theitems in the CartItems table for that given cartID to the OrderItemstable given a new orderID.I will know the cartID and orderID ahead of time and would like tosend them both into a stored procedure and have the transfer takeplace.Example:take this data...CartItems (table)--------------------------------------cartID | itemID | quantity | price--------------------------------------12345 2 1 12.9512345 7 2 17.95and make it this data...OrderItems (table)--------------------------------------orderID | itemID | quantity | price--------------------------------------00001 2 1 12.9500001 7 2 17.95via some stored procedure that I send (@cartID,@orderID)Any help would be greatly appreciated!!

View 5 Replies View Related

Comparing Similar Tables - Removing Duplicate Or Repeated Data

Sep 30, 2007

It seems that there should be a solution for my situation, but for the life of me I can't seem to figure it out.

I need to compare two "like" tables, containing similar data. Tbl 1 is "BOOKED" (which is a snapshot of inventory) and tbl 2 is "CURRENT" (the live - working inventory table). If I write my query as follows the the subsequent result is "duplicate" data.




Code Block
SELECT booked.item, booked.bin, booked.quantity, current.bin, current.quantity
FROM BOOKED
LEFT JOIN
CURRENT
ON booked.item = current.item







No matter what type of join I use, there is duplicate data displayed for each table. For example, if there are more bins in the BOOKED table that contain a certain product then the CURRENT table will repeat data and vica versa.

As follows:







Item
Bin
Quantity
Bin
Quantity

12345
A01
500
A01
7680

12345
B01
6
A01
7680

12345
C01
20
A01
7680

54321
G10
1032
E15
1163

54321
G10
1032
F20
523

54321
G10
1032
H30
750

98765
Z20
7000
Z20
8500

98765
Y15
2500
Y15
3000

98765
X10
1200
Y15
3000

What I would like to do is display Bin and Quantity only once and the repeating values as NULL or [BLANK]. Or, to display all of the bins from both tables and only the quantities from each table in relation to the bin found in that table, returning a "0" if no quantity exists.

This is what I'm after:







Item
Bin
Quantity
Bin
Quantity

12345
A01
500
A01
7680

12345
B01
6
B01
0

12345
C01
20
C01
0

54321
G10
1032
E15
1163

54321
F20
0
F20
523

54321
H30
0
H30
750

98765
Z20
7000
Z20
8500

98765
Y15
2500
Y15
3000

98765
X10
1200
X10
0



Is this possible? If so, how?

I also might add that it is ok for each table to contain multiple entries for any given item. This is basically being requested as an inventory variance report - inventory before physical count and immediatly after physical count - and will only be run once a year.

-----------------------------------------------
Just thinking out loud here:
What if I created three subqueries, the first containing only BOOKED information, the second containing only CURRENT information and the third being a UNION of both tables? Something like this:




Code Block
SELECT q3.bin, q1.item, ISNULL(q1.quantity, 0) as QTY_BEFORE, ISNULL(q2.quantity, 0) as QTY_AFTER

FROM

(select item, bin, quantity
from BOOKED)q1
Left Join

(select item, bin, quantity
from CURRENT)q2
on q1.item = q2.item
Left Join

(select bin, item
from BOOKED
UNION
CURRENT)q3
on q1.item = q3.item

Order By q1.item





I don't know if I wrote the UNION statement correctly, but I will have to try this when I get back to work...


Any suggestions?

View 7 Replies View Related

How To Group Similar Column Name And Sum The Similar Column Name Together

Apr 10, 2008

Hey Gurus,

I have a problem on getting the sql statement which will group similar column name and sum their number together(another column).


A million thanks in advance.

View 5 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

Fill Data Grid With Data From JOIN Query

Jul 8, 2013

I am working on a school project and have come up against a bit of a sticking point. I am supposed to be creating a very basic OMS, the teacher themselves have said they do not know how to do this (in previous years it has all be done via Access) but apparently I am a lucky one to be doing it in SQL this year.

So I have 2 tables for products in the system

products
+-----------+------------+
|productid |productname |
|Int |varchar(50) |
+-----------+------------+

productdetail
+---------+----------+------------+------+------+
|detailId |productid |description |price |stock |
|Int |Int |Text |Money |Int |
| |FK_From_ | | | |
| |productid_| | | |
| |products | | | |
+---------+----------+------------+------+------+

One of the user requirements of the OMS is to fill a data grid with product name and the product details which I have the query for or rather I have created a view for, which is then queried from a stored procedure.

CREATE VIEW [dbo].[v_stock]
AS SELECT tab_products.productname, tab_productdetails.description, tab_productdetails.image, tab_productdetails.price, tab_productdetails.stock
FROM tab_productdetails INNER JOIN
tab_products ON tab_productdetails.productid = tab_products.productid

The problem I am having is then returning the data from this query into a data grid, I think the reason is because when I attached the stored procedure to a table and then call that procedure via the table adapter there is a mismatch of the schema - specifically the table it is attached to does not contain the column "productName".

I am thinking I need to create a temporary table to fill the data grid with - however, I am not sure how I would create a temporary table.

Is there something I am missing or not done correctly. As far as I can tell the queries work as when I preview them they produce the expected results.

View 1 Replies View Related

Join Three Data Sets From Different Data Flows Into One Txt File

Mar 9, 2008

Hi, I was wondering how it is posible to join three data sets from different data flows into one txt file.
Let's explain a little more:


I have 3 dataflows. Each of them connect to sql server and and by a SQL command, they bring data into SSIS.

Each SQL command differ between them. So each data set have different columns (they dont have the same format). Also the amount of columns differ between each one.

What I need is to join the three data sets into one txt file. How can I do this? It is posible to join them with different data set formats into a txt file?

Is this the best way to join different data? It is better to use as many OLE DB Sources are needed instead of different data flows?
Thanks for your help!

View 7 Replies View Related

Exporting Data From A Merge Join From One Data Flow To Another

Mar 1, 2006

Hi,

Does anyone know if it is possible to point data that underwent the "merge join" transformation (in one data flow) to the following data flow? I don't want to recreate all that merging, sorting and calling the same sources again in the following data flow if the data that I am using exists in the previous data flow. The merged data is simply too big to export to an excel file, so does anyone have any ideas? Thanks!

View 8 Replies View Related

Similar To PhpMyAdmin For MS Sql?

Apr 11, 2005

Is there any program similar to phpMyAdmin for MS SQL servers?

Thanks in advance

View 5 Replies View Related

Do I Need DatePart Or Similar

May 11, 2006

I have a function that uses the following statement in it

SELECT src_terrier.Areacode, src_terrier.siteref, src_terrier.estatename, src_terrier.Securitised, src_terrier.unitref, src_terrier.unittype,
src_terrier.unittype_count, src_terrier.tenantname, src_terrier.tenantstatus, src_terrier.tenantstatus_count, src_terrier.unitstatus,
src_terrier.unitstatus_count, src_terrier.floortotal, src_terrier.floortotocc, src_terrier.initialvacarea, src_terrier.initialvacnet, src_terrier.TotalRent,
src_terrier.NetRent, src_terrier.FinalRtLsincSC, src_terrier.ErvTot, src_terrier.tenancyterm, src_terrier.landact, src_terrier.datadate,
src_div_mgr.div_mgr, src_portfolio_mgr.portfolio_mgr, src_centre_list.propcat, src_tbl_rental.budgeted_net_rent,
src_tbl_rental.budgeted_occupancy
FROM src_terrier INNER JOIN
src_centre_list ON src_terrier.siteref = src_centre_list.Site_Ref AND src_terrier.Areacode = src_centre_list.Division INNER JOIN
src_div_mgr ON src_centre_list.Division = src_div_mgr.division INNER JOIN
src_portfolio_mgr ON src_centre_list.Portfolio_no = src_portfolio_mgr.portfolio_no LEFT OUTER JOIN
src_tbl_rental ON src_terrier.siteref = src_tbl_rental.site_ref

WHERE (src_terrier.datadate = @dt_src_date) AND
(src_terrier.Areacode = @chr_div) AND
(src_centre_list.Portfolio_no = @vch_portfolio_no) AND
(src_centre_list.propcat = @vch_prop_cat) AND
(src_tbl_rental.site_ref = src_terrier.siteref)

The problem I have is that the 'src_terrier.datadate' is passed through as mm/dd/yyyy (which I do actually want to change to dd/mm/yyyy as that is how the data is stored) however, the src_date within the table src_tbl_rental is only set to 01/mm/yyyy. When I put an inner join on the date element it obviously does not find it as the sample data I am using is as follows

src_terrier = 28/04/2006 and src_tbl_rental is 01/04/2006. Therefore if I pass the same parameter value through the dates are not the same and I get no data at all.

How can I specify that for the purposes of the src_tbl_rental element of the select query, that I only want it to match the mm/yyyy part of the src_date.

Therefore if some passes in
28/04.2006 it will get the records from the terrier table that match that date, and only the records from rental that match the 04/2006 part of the date.

Anybody confused by that , cause I am!

Regards

View 6 Replies View Related

Is There St Similar To Directoryinfo In RS?

Apr 28, 2008

hello there.

is there any case for getting the directory/file structure on the ReportServer?
something similar to "DirectoryInfo".

i'm using the webservice
best would be putting the url (e.g. "http://localhos/reportserver/reportgroup1") to a function and get at least an array of filenames in this folder back.

is there any way to solve this?

thanks in advance, tobias

View 1 Replies View Related

Sys.sql_dependencies Or Similar?

Sep 11, 2007

Hi!
I'm about to write some code that generate TSQLdoc.
For that I would like to show dependencies.

What will the best way to get actual info about
which procedures use this proc
which procedures or functions do this proc or func use?


Thanks

View 2 Replies View Related

Function Similar To ISNULL()

Oct 6, 2005

I'm constructing a single string of several counts with concatenated labels using SQL and want to not show zeros (or their labels). Is there a function within an SQL statement that will let me do this? ISNULL() sort of does this, but I really need to test for zero instead of NULL to eliminate noise data from the string.

View 2 Replies View Related

Similar To Statspack/AWR Report

Dec 13, 2007

Is there anything similar to AWR/statspack report in SQL Server 2005.

View 4 Replies View Related

Difference Between Two Similar Queries

Feb 21, 2008

Hi All,

Is there any difference between the two queries given below..I am not able to find any but am not sure. Kindly help.

A)

select a.* from( select top 1 hs.last_modified, hs.price, hs.revision_date
from history hs where hs.last_modified < '06-Jan-2008' order by hs.last_modified desc)a
order by a.revision_date desc

B)
select hs.last_modified, hs.price, hs.revision_date
from history hs where hs.last_modified < '06-Jan-2008'
order by hs.last_modified desc, hs.revision_date desc




Thanks,
Pradeep.D

View 4 Replies View Related

Using Somthing Similar Than Squence In Ms Sql

Feb 6, 2007

Hi,
I need something like a sequence in a datafield of my table. (unique number in the table) is a uniqueidentifier the right thing to choose? and if yes, how to I insert a new value into the that table:

a) from the SQL Enterprise Manager?
b) from a JAVA program using jdbc?

thanks for all hints.

View 2 Replies View Related

Similar To COALESCE Function

Nov 4, 2004

I have three fields in a table say [F1, F2 & F3]. I need to fetch anyone of these three fields which has the maximum value between them.

In Simple words i'm looking for some function which is similar to COALESCE function which returns the first NOT NULL value of the fields that were passed as arguments.

FYI I'm using SQL Server 7.0 which does not supports UDF's

Earlier response appreciated

Thanks and Regards
Chandru

View 3 Replies View Related

Add Similar Fields To Many Tables

Dec 13, 2004

Folks, i have to create four fields in every user table within my database:

CREATED_BY VARCHAR(25), CREATED_DATE [DATETIME], MODIFIED_BY VARCHAR(25), MODIFIED_DATE [DATETIME]

There are more than hundred tables, so i wanna automate this. i am tryin to do this in a cursor: please guide!

declare @name VARCHAR (50)
declare cur cursor
fast_forward
for select name from sysobjects where type='u' and status not like '-%'
open cur
WHILE (1=1)
BEGIN
FETCH NEXT
FROM cur
INTO @name
IF @@fetch_status = 0
BEGIN
ALTER TABLE @name
ADD created_by [VARCHAR] (25)
GO
ALTER TABLE @name
ADD created_by [VARCHAR] (25)
GO
ALTER TABLE @name
ADD created_date [DATETIME]
GO
ALTER TABLE @name
ADD modified_by [VARCHAR] (25)
GO
ALTER TABLE @name
ADD modified_date [DATETIME]
END
ELSE
BREAK
END
DEALLOCATE cur


I also want that if one column for a table exists; the other columns should be created rather than it quits.


Howdy!

View 4 Replies View Related

Merge And Sum Similar Records

Nov 20, 2012

I have the below in a table - TABLEA

Ref, Date, TIME, Code, Minutes
01117,2012-01-02, 541,BASIC,240.0
01117,2012-01-02, 541,BASIC,105.0

And I am trying to insert this into another table TABLEB but it wont allow as I am getting a duplicates error because of the unique Indexing on the table.

Ref,Date,Time,Code

Ideally if I could run a query on TABLEA so that it would merge and sum the minutes where REF,Date,TIME,CODE are the same.

i.e., the above would become

Ref , Date , TIME, Code, Minutes
01117,2012-01-02, 541,BASIC,345.0

Is this possible?

Another option that would work for me is the TIME column info isnt required to remain at 541.

If there was a count increment on the rows it would allow the import to rum.

ie if the above became

Ref, Date, TIME, Code, Minutes
01117,2012-01-02, 1,BASIC,240.0
01117,2012-01-02 ,2BASIC,105.0

It would also import correctly.

The first option is which I would prefer.

View 2 Replies View Related

Combine Authors With Similar IDs

Mar 13, 2014

Im trying this simple query, where if a book has the same ID but different names it should be shown in one row and not two...

Now it is showing

- 1 AuthorDude
- 1 AuthorGirl
- 2 Authorblabla

While it should show

- 1 AuthorDude, AuthorGirl
- 2 Authorblabla

SELECT a.book_id, b.Name
from BOOK_SALES a
left outer join
(
select Book_id,is_primary,
STUFF((select ', ' + Name from BOOK_CONTRIBUTOR B where B.BOOK_ID = A.BOOK_ID
for xml path('')),1,1,'') Name
from BOOK_CONTRIBUTOR A
group by Book_id,IS_PRIMARY
) b on a.BOOK_ID = b.BOOK_ID

When i do a inner join, it would just show many Book_ID`s, but with the authors combined.

[URL] ....

View 3 Replies View Related

Find Out Similar Columns

Apr 19, 2007

i like to write a sql query to find out similar columns in different tables.

i have something like this. but my logic is wrong.

select *
from information_schema.columns a
join information_schema.columns b
on a.column_name = b.column_name
and a.table_name <> b.table_name

View 1 Replies View Related

How To Go About Adding Similar Tables?

May 26, 2007

I have a table that I am basically reduplicating a couple of times for each part of this database that I want to create.

Each table basically has the same data: The tables will be called motherTable, fatherTable, sonTable, daughterTable and so on.

I am pretty much using the following in each column: UserID, MotherID(or FatherID or SonID, etc., etc. and so on for each unique table), FirstName, LastName, MiddleName, BirthPlace, Photo, Age.

I don't see an option to copy a table and just modify the second ID part and rename that table accordingly.

How can I make this an easier way of creating these similar tables without retyping all these columns over and over again?

Thanks in advance.

View 5 Replies View Related

Join Into New Data

Jan 19, 2012

I need joining 2 tables and putting the result into a new table.

Table export has the following columns:
Period, Actual, Company, Currency, Account, Amount, a,b,c,d,e,f,g,h,i,j,k

Table cc_split has the following columns:
Company, Fun_Account, CC_Account, x, y, Split

The new table called export2 has exactly the same values as export i.e. :
Period, Actual, Company, Currency, Account, Amount, a,b,c,d,e,f,g,h,i,j,k

So what I need to join from export and split into export2 are company, cc_account (that shall go into account column of export2 together with the account of export) and the amount, which shall be ( split column * amount column of export), the rest values shall be the same.

So what I have so far is

Code:
INSERT INTO EXP_DATA_2(PERIOD, ACTUALITY, COMPANY, CURRENCY, ACCOUNT, AMOUNT,
EXTDIM1, EXTDIM2, EXTDIM3,EXTDIM4,JOURNAL_TYPE,C_COMPANY,
COMPANY,C_DIM, TRANAMOUNT, TRANCURR,REGION, TRANSF_DATE)
SELECT COMPANY, CC_ACCOUNT, SPLIT
FROM EXP_DATA INNER JOIN CC_SPLIT ON EXP_DATA.COMPANY=CC_SPLIT.COMPANY AND
EXP_DATA.ACCOUNT = CC_SPLIT.CC_ACCOUNT
WHERE EXP_DATA.PERIOD IN ('1102', '1103', '1104')]

So at the end basically table exp_data 2, shall have the same values as exp_data but the account column shall include the same values of account column of exp_data plus the values of cc_account of cc_split table. And also the amount column shall be the multiplication of the column split from cc_split * amount of exp_data

I have realised that I need an alias, maybe a for exp_data and b for cc_split.

View 4 Replies View Related

Select Command Done Similar To Insert?

Aug 2, 2007

I did a successful Insert to a SQL Server today in .NET VS2005.
But before I insert I figure I better make sure the part does not allready exist in the table.
Can a check the command to determine if it has a boolan value of False and if so to INSERT as before?  Dim myCommand As New SqlClient.SqlCommand

myCommand.CommandText = "Select PartNumber From Pricing Where PartNumber = '" & var0 & "'"

'myCommand.CommandText = "INSERT INTO Pricing (PartNumber, ListPrice, PartDescription, ProductClassCode, ProductClassDescription, ProductFamilyCode, ProductFamilyDescription, ProductLineCode, ProductLineDescription) VALUES('" & var0 & "', " & var1 & ", '" & var2 & "', '" & var3 & "', '" & var4 & "', " & var5 & ", '" & var6 & "', '" & var7 & "', '" & var8 & "')"

myCommand.Connection = con


con.Open()
myCommand.ExecuteNonQuery()
con.Close() 
 

View 4 Replies View Related

Array (or Similar Thing ) In Sql Server

Jul 4, 2005

I would like to write a fun or stored procedure to do some operation. It require me to know that what category is currently belong to certain people(people_table: category_table1               to           Many)However, when i use the select statement in stored proc, it return a set of result, not a scalar , therefore, i cannot use the variable to hold it. In addition, there are no array in SQL server.Question:1. Is there any way to hold the collection of result(like array)?2. Also, how to determine to use fun or stored procedure?(Since a integer is need to return by them)Thx

View 4 Replies View Related

COMMAND SIMILAR TO SPOOL IN ORACLE

Jan 16, 2002

Hi all,
I have a table with the list of tables I need to drop. So basically before droping those tables I need to disable the FK and PK constraints.
So I want to spool out the out of this script.
SELECT 'ALTER TABLE ' +
QUOTENAME( c.TABLE_NAME ) +
' NOCHECK CONSTRAINT ' +
QUOTENAME( c.CONSTRAINT_NAME ) AS ALTER_SCRIPT
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS c
WHERE CONSTRAINT_TYPE = 'FOREIGN KEY'

Is there a way to store the output of this script in a .sql file so that I could execute it.
Any thoughts will help!
Thank you!

View 5 Replies View Related

Does Anyone Know Of A Great Access Help Site Similar To This.

May 17, 2000

Does any one have information on any good Access Sites that are similar to this one, which could be helpful in completing some task. Thanks.

View 1 Replies View Related







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