Merge Two Fields From Two Different Tables Into One
Aug 24, 2004
If possible, I would like to create a view using two different tables, but with the fields merged (ie. create one table from two tables). The table structures are pretty much the same. Can you do this from a singe SQL statement? Any ideas? My only alternative is creating a temp file that inserts records from both tables, but I want to avoid doing that.
View 6 Replies
ADVERTISEMENT
Feb 20, 2008
How can I create a Table whose one field will be 'tableid INT IDENTITY(1,1)' and other fields will be the fields from the table "ashu".
can this be possible in SQL Server without explicitly writing the"ashu" table's fields name.
View 8 Replies
View Related
Jul 23, 2005
What is the best way to go about merging the results of two fields inthe same table?I have two different fields that hold lists of names, some of themidentical, some different. From those I'd like to generate a mergedlist with all the distinct names.For example:Field1 contains: Jack, Joe, Jim, PaulField2 contains: Peter, Paul, Joe, JimThe result should be: Jack, Joe, Jim, Peter, Paul
View 5 Replies
View Related
Mar 22, 2006
Hello, I need your expert help:
I have two tables (ship2005 and ship2006) all with same structure
Sold_to
Week
Year
Units
Dollars
Style
I have to merge them together, and add some other columns from other tables
Custmstr (director) and stylemstr (style) based on Sold_to
In the format so I’m able to see 2005 week, 2006 week, 2005 unit, 2006 unit, 2005 dollars, 2006 dollars and so on.
This one is working, but forever…
where Custmstr.Sold_to *= ship2005.Sold_to
and Custmstr.Sold_to *= ship2006.Sold_To
and stylmstr.style_num *= ship2005.style_number
and stylmstr.style_num *= ship2006.style_number
And another thing: how can I populate the Year column for both?
Thank you very much
View 4 Replies
View Related
Sep 22, 2006
Hello All,
I have two column firstname,lastname.I just want to merge both to one.
Like john ,david
it should be johndavid into one.Please its urgent
View 6 Replies
View Related
Nov 21, 2006
Hi guys! I'm trying to figure out how to join 3 tables, but I can't seem to find a solution. What I want to do is to put table 1, table 2 and table 3 into table_merged.
table_merged = table 1 + table 2 + table 3
Is it possible to merge tables even if they have different fields?
Please help.
Onegai shimasu...
Thanks in advance!
View 1 Replies
View Related
Aug 21, 2012
I am trying to update values in two tables (approx 1-2 million records).
I have decided to use a MERGE statement, however have been unsuccessful to do so.
Below is an example of the statement.
The error is receive is "Incorrect syntax near '('." right after the MERGE line.
Is it not possible to use this syntax ?
Example:
[CODE]
MERGE
( SELECT a.id, b.id2
FROM TableA A
JOIN TableB B
[Code]....
View 5 Replies
View Related
Feb 18, 2014
I have two totally different tables with completely different data fields. Also, there is no common relationship between these two tables. However, I want to pick few data fields from the each table and merge into a new table! Is this even possible?
View 9 Replies
View Related
May 27, 2014
I've One table that contains all current appointments booked as below.
RNappt_idclinic_idderived_location_idprovider_idappt_date_timeappt_date_endtime
1102186011435/27/14 8:305/27/14 9:00 AM
2102196011435/27/14 9:305/27/14 10:00 AM
3102206011435/27/14 10:305/27/14 11:00 AM
4102216011435/27/14 14:005/27/14 2:30 PM
5102226011435/27/14 16:005/27/14 4:30 PM
6102236011435/27/14 16:305/27/14 5:00 PM
for Same Clinic,location and Provider there's a schedule data for same day 24 hours
having every five mintues as below:
clinic_idderived_location_idprovider_idstart_timeendtimeunblock
601143 8:01 8:040
6011438:05 8:100
601143
60114313:0113:041
601143
60114313:5514:001
601143 1
60114317:5518:000
60114323:550:001
for rows having no start and endtime assume it as regular intervals.
So i need to show available appointment with duration one hour with the available schedule which is for every five minutes
Like My first appointment for today starts at 8:30 but 8- 8:30 is unblock so there could be an appointment but as this chunk is less than 60 so need to create it
For Schedule table below is what i've to create for temporary basis as this will be available in nightly load in a table.
DECLARE @num int=5
,@LASTtime TIME =CAST('23:55' as TIME)
,@Time TIME =CAST('00:00' as TIME)
,@Timeprev TIME =CAST('00:00' as TIME)
WHILE ( @Time<>@LASTtime)
BEGIN
[code]....
View 8 Replies
View Related
May 15, 2006
Hi,I hope this is the right place to ask this question. If it is not,please let me know a more appropriate place.I have two tables.CREATE TABLE tblEmployees(EmployeeID int identity NOT NULL,LastName varchar(50) NULL,FirstName varchar(50) NULL,);CREATE TABLE tlkpDept(DeptID char(5) NULL,Name char(10) NULL,LongName char(50) NULL);Now I want to create a view called AssignedTo. [The application I'mdoing, will track the status of our customer requests. Each requestcan be assigned to either an individual employee or an entiredepartment]I want the view to have two columns, ID and LongName. ID should beeither the DeptID or the EmployeeID. The LongName column should beeither the LongName or the FirstName + LastName.I'm not even sure how to begin to write such a complex SQL.EnterpriseManager is being less than helpful too.Can anyone help?Thanks in advance.-Tom
View 4 Replies
View Related
Dec 6, 2005
Hey all
For performance reasons i want to move the Merge Replication tables in a DB of mine (mainly MSMerge_Tomestone and MSMerge_Contents) to a seperate filegroup ... it's a heavy transactional DB and the index fragamentation rate is quite phenominal!
View 6 Replies
View Related
Nov 7, 2006
I need to take certain items of data from four different tables and out them into one table.
Unfortunately my source data's version of SQL does not support the LEFT JOIN keyword which has left me with a bit of a problem.
I saw the merge join in SSIS and used it to get data from two of the tables and stick them in the destination and it all worked fine.
That got me thinking, is it possible to create a second merge join transformation within the same data flow task for the remaining two tables and then join the output of both the merge joins to give me the data I need from all four tables in one output?
View 1 Replies
View Related
Apr 1, 2004
Hi all,
I'm not sure how easy of a task this is, or how to go about it, so I thought I'd ask here. I am doing a major overhaul to my site and am re-programming the backend which involves re-formatting my tables, table names etc.
What I want to do is set up a new table in the format I want for the new site, but still be able to have the live data that is being submitted to the site now, be entered into the new table so that I don't have to shut down the site for days to transfer and reformat data. Example
CURRENT SITE
Table 1
Field1: Name
Field2: Address
NEW SITE
Table 1
Field1: Name
Field2: myAddress
Field3: City
I want to be able to somehow map the two together so that when data is entered into the Name field on the current site, that same name is also inserted into the new site table as well. Mapping like this:
(current site)Name -> (new site)Name
(current site)Address -> (new site)myAddress
The city field would be left unaffected as that data would only be entered once the new site is up and running.
I know I could do this from a stored procedure on the exiting site or by re-writting all of my SQL to insert into both tables, but right now all of the SQL is hardcoded into the pages and I have A LOT of pages. Is there a way to map the tables together from within SQL Server?
Cheers,
Jeff
View 5 Replies
View Related
Oct 8, 2004
Hi All,
I need to get the names of tables and fields (or atleast the fields) from a database. Is there a query I can use that will return what all the db's tables and those tables fields are?
Thanks
Lee
View 3 Replies
View Related
Mar 15, 2001
Hi,
I have a database with approx 95 tables. I would like to get a printout of each table, the fields contained therein and the field type
(i.e the information displayed when rightclicking a table in Enterprise Manager and selecting Properties).
I have tried to use the diagram function but due to the large number of tables the diagram is very complex and would have to be printed out on a huge sheet of paper to make it legible. I have also looked at the SP_HELP stored procedure but can't seem to get the syntax correct to display properties on all tables (info on one table is no problem).
Any ideas ?
Thanks,
Tim H
View 1 Replies
View Related
Aug 4, 2005
I am working with the article that MAK wrote on SecurityLogs http://www.databasejournal.com/features/mssql/article.php/3515886
I have completed this, but I have made some changes to the database (for normalization to 3NF purposes). I now have problems with a query.
I am trying to "Insert a new record in a table if it does not already exist in the table". To try to clarify I perform the following query:
INSERT INTO Tmp_Event
SELECT DISTINCT EventID, EventType, EventTypeName from Tmp
Which gives me the Tmp_Event table consisting of EventID's etc. (no duplicates). What I then want to do, is compare the 'Tmp_event' table and an already existing 'Event' table. These two tables are in fact identical. I would like to insert any records from 'Tmp_Event' into 'Event' if they do not already exist in 'Event'.
This query gives me all records that do not exist in 'Event'
SELECT EventID, EventType, EventTYpeName from Tmp_Event
WHERE EventID NOT IN (SELECT EventID from Event)
How can I change this query into performing an INSERT INTO Event as well?
Hope this makes sense :)
-Silia
View 2 Replies
View Related
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
Jan 30, 2008
For example, I have 2 tables that have very similar fields
Table 1 Table 2
ShipRpt ShipRpt
invoice invoice
total sold total sold
Is it possible to compare each of these fields and return any record that has non matching data? I would join the tables on the shipping report or invoice and only compare the total sold field. If the invoices match and the total sold is different in each table, can I just return the 1 record?
View 2 Replies
View Related
Feb 24, 2006
I am using a hosted MSSQL 2000 database that powers the backend of mywebsite. Website visitors interact with it via ASP pages I havedeveloped. I also have an internal FileMaker 7 database thatperiodically synchs with it via Filemaker's ODBC functionality.Several times now, I have come in one day to discover that my ASP pagesdon't work. When I look into it, one of my MSSQL tables will be missinga few fields. There is nothing in any of my code that sends an ALTERTABLE command or any other command that affects table structure. Thesedeletions of fields is totally random.The most recent example was with a table called FreeTeacherSubs. I justdiscovered today that three fields went missing:HowDidYouHearAboutYES TEXTFollowUpCallOrEmail TEXTHowMaterialsFit TEXTSuffice to say I am baffled! Has anyone ever experienced fieldsdisappearing from their tables?Kevin
View 2 Replies
View Related
May 15, 2008
hi guys,
i have 3 tables (T1, T2, T3), each with the same structure:
ID1 -> char(10)
ID2 -> char(12) NULL
ID3 -> char(10)
Value1 -> money
Value2 -> money
Value3 -> money
Note1 -> Text
Note2 -> Text
ID1+ID2+ID3 is the clusterd unique key in each table
what i want:
ID1, ID2, ID3 (with distinct occurencies of all 3 tables), T1.Value2, T2.Value2, T2.Value3, T3.Value1, T3.Note1
what i tried is to get all possible rows with
SELECT ID1,ID2,ID3 FROM T1
UNION
SELECT ID1,ID2,ID3 FROM T2
UNION
SELECT ID1,ID2,ID3 FROM T3
but i dont know how to join or add the other columns. maybe with
WITH RowList (ID1,ID2,ID3) AS ( ... code above.... ) SELECT ...
any ideas?
thx
View 10 Replies
View Related
Oct 26, 2015
I have two temp. tables. I am trying to show the agents how makes the sales and the ones how didnt make sales based on the time that they clock in. One table is called #sales which has only the agents that make sales and other tables is #hours which has both agents that do not make sale. the problem is that I can not get both agents to show on my report. I tried different ways but I could not. #sales table uses (select statement from AmountStats table that stores only the agents who make sale). #hours table uses different tables to store all gents who makes sale and ones that are not making sale.Â
declare
@start datetime,
@end datetime,
@campaignId uniqueidentifier,
@campaignName varchar(250),
@segment varchar(50)
set @start = '2015-10-07'
set @end = '2015-10-20'
[code]....
how to merge these two columns from #sales and #hours tables without duplication.
View 6 Replies
View Related
Oct 12, 2006
I feel sure that this is a very naive question, but it is freeky me out that I can solve it. With SQL server what is the easiest way to make a field other than the Primary key unique?Would appreciate help with this. ThanksPaul
View 3 Replies
View Related
Nov 17, 2006
Hi there,
I have a fairly generic question regarding database design.
I am working on my first database using SQL Express.
I am testing the database by inserting records into the pre defined tables.
Sometimes I forget to input text into a non null field. When
this happens it displays an error and then skips a few rows
which makes my row numbering messy. For example say I have
Row 1, Row 2 Row 3 all nicely formatted but on Row 4 I make a mistake
this row then disapears and their is gap between 3 and 5 where 4 was.
Although I am just testing, I was wondering what happens in a real
scenario if an inexperienced data input person makes a few mistakes it
makes the database numbering systems look bad. In this case
is it common to make most fields NULL to allow for admin errors??
View 8 Replies
View Related
Oct 27, 2000
Can I add a description to a table or field? The way access gives you to add a description to a field.
Thanks!
View 1 Replies
View Related
Aug 16, 2006
As part of a project documentation I want to list out the fields of all the tables to say Excel to plug in a description of the field and other notes.
Is there a tool in EM that would facilitate? Or, is there a utility that would work or a SQL script? Any recommendations is greatly appreciated.
Thanks,
Peter
View 7 Replies
View Related
May 19, 2008
Hi guys,
please help.
I use to copy one column from one database to another database. What query should I use?
moreover,
How can I convert this
code
000001
the result would be
code
1
thanks!
View 5 Replies
View Related
Jan 24, 2007
Amir writes "Dear Team Members;
Im writing a program in ASP language which it is using SQL Server for database.
I want to know how to create a link between fields of two tables. For example:
I have a table named: Projects containing:
p_name
status
date
member1
member2
and another table named results containing:
p_name
s_status
status1
status2
I want to create a link between field s_status of STATUS table and field status of table Projects
Users are sending data to table projects, when a user send some data to status of projects, I want this link to send data from status in project to s_status of results.
Could you please help me how to do it?
Regards.
Amir Zandi"
View 1 Replies
View Related
Sep 27, 2006
Question.I have a new table that I am adding to a script that I wrote. Thistable has 3 fields, the first 2 fields are used in the on statement asbeing = other fields in the script.The first field always has data in it, but the 2nd field is sometimesnull.So my problem is if both fields have data in them and they both matchto the data in the fields that I am linking them to, then it returnsthe 3rd field without a problem. However if the 2nd field is null thenit is returning a null for the 3rd field. I have checked and the fieldthat I am linking to is null also.So if I haveselect t1.field1, t1.field2, t2.field1, t2.field2, t2.field3from table1 t1join table2 t2on t1.field1=t2.field1 and t1.field2=t2.field2with 2 records in each tabletable1: record1: data, datarecord2: data, nulltable2: record1: data,data,datarecord2: data,null,datawhat I get from the script isrecord1: data, data,data,data,datarecord2: data,null,data,null,nullI would expectrecord2: data,null,data,null,dataI hope this makes sense, I didn't want to post the entire actual scriptas it is about 150 lines long.Thanks in advance.
View 5 Replies
View Related
Apr 6, 2001
Hi, eveyone..
I have a problem.
One of developer deleted Merge Replication Job.
However there is no doc for that replication.
What I want to know is like this:
which tables are in that replication?
Is there any system or user tables track down these replication as well as configuration in that replication?
Thanks in advance:-))
Jay
View 1 Replies
View Related
Feb 3, 2014
Merging table :
--------Dummy TABLE
create table #Tbl1 (date1 date,WSH varchar(10),ITN int,Executions int)
insert into #Tbl1 (date1 , WSH , ITN , Executions)
select '20130202' ,'ABC', 1 , 100
union all
select '20130203' ,'DEF', 1 , 200
[Code] .....
I want Result like this :
date1 WSH ITNExecutionsMCGPositions
2013-02-02 ABC 1 100 2 500
2013-02-03 DEF1 200 NULL NULL
2013-02-05 NULLNULL NULL 2 600
View 2 Replies
View Related
Apr 29, 2015
If you have 2 tables with the same columns and you would like to see all distinct records in a result of a select and also the information in the records which table the record comes from (for instance: from table A or from table B or bot tables contain it) what should you do?
View 5 Replies
View Related
Mar 31, 2008
Hello.
I need some help constructing a query i need to run on my database. I need to add 2 fields to every table in my databse. However, some of the tables already have1 or both these fields so i need to somehow do a check if the dield already exists. If it does not create the fields. Im using a MS SQL express 2005 server.
Could anyone help me construct this. Im pretty novice at SQL.
Thanks.
View 7 Replies
View Related
Mar 25, 2008
How can i print or export all fields for all tables in my sql 2005 db?
View 3 Replies
View Related