SQL Server 2008 :: Append Records With Different Number Of Columns?

Feb 16, 2015

I have a table of Customers & their data in about 20 Columns.

I have another table that has potential Customers with 3 Columns.

I want to append the records from Table 2 onto Table 1 to the Columns with the same names.

I've thought of using UNION ALL or Select Insert but I'm mainly stuck on the most efficient way to do this.

There is also no related field that can be used to join the data as these Customers in table 2 have no Customer ID yet as they're only potential Customers.

Can I just append the 3 columns from Table 2 to the same 3 columns in table 1?

View 2 Replies


ADVERTISEMENT

SQL Server 2008 :: Divide Total Rate By Number Of Records

Jun 22, 2015

my table includes detailed records with total Rate repeated in each record:

CREATE TABLE Table1
(
Providerid varchar (6) NOT NULL,
Providername char (30) NOT NULL,
Clientid varchar (15) NOT NULL,

[code]....

View 1 Replies View Related

SQL Server 2008 :: Calculate Number Of Months Between Dates For Multiple Records?

Oct 7, 2015

I have a challenge and I'm not sure the best route to go. Consider the following dataset.

I have a table of sales. The table has fields for customer number and date of sale. There are 1 - n records for a customer. What I want is a record per customer that has the customer number and the average number of months between purchases. For example, Customer 12345 has made 5 purchases.

CustomerNumber SalesDate
1234 05/15/2010
1234 10/24/2010
1234 02/20/2011
1234 05/02/2012
1234 12/20/2012

What I want to know is the average number of months between the purchases. And do this for each customer.

View 6 Replies View Related

SQL Server 2008 :: Identify Columns And / Or Tables From Records

Mar 3, 2015

I'm using MS SQL Server 2008 and I'm trying to figure out if it is possible to identify what tables / columns contain specific records.

In the example below information generated for the end user, so the column headers (Customer ID, Customer, Address, Phone, Email, Account Balance, Currency) are not necessarily the field names from the relevant tables, they are simply more identifiable headers for the user.

Customer ID CustomerAddress Phone Email Account Balance Currency
js0001 John Smith123 Nowhere Street555-123-456 jsmith@nowhere.com-100 USD
jd2345 Jane Doe 61a Down the road087-963258 jdoe@downthe road.com-2108 GBP
mx9999 Mr X Whoknowsville 147-852369 mrx@whoknows.com0 EUR

In reality the column headers may be called eg (CustID, CustName, CustAdr, CustPh, CustMail, CustACBal, Currency).

As I am not the generator of this report, I would like to know whether or not it is possible to identify the field names and / or what tables they exist in, if I were to used the report info to search for it. For example, could I perhaps find out the field name and table for "jd2345" or for "mrx@whoknows.com", because the Customer ID or Email may not be what the actual fields are called.

I'm not a DB admin and I don't have rights to do a stored procedure on the server. I'm guessing what I want is not so simple to do, but is it possible to do via a query?

View 2 Replies View Related

SQL Server 2008 :: How To Pivot Unknown Number Of Rows To Columns Using Data As Column Headers

Sep 10, 2015

I have a single table that consist of 4 columns. Entity, ParamName, ParamsValue and ParamiValue. This table stores normalized Late Fee related parameters for apartments. The Entity field contains a code that identifies the apartment complex. The ParamName in a textual field that contains the name of the parameter that the other 2 fields define the value for; ParamsValue and ParamiValue. If the Late Fee parameter (as named in ParamName is something numerical then the value for that parameter can be found in ParamiValue else its in ParamsValue.

I don't know if 'Pivot' is the correct term to use for describing what I am trying to do because I've looked at the Pivot examples and I don't see how that will work for this. Using the Table and data as provided below, how would I construct a query so that I get 1 row per Entity in which the columns are the ParamsValue or ParamiValue for the ParamName listed in the column header (for the query)?

Below is the DDL to create the table and populate it.

USE [DBA_UTIL]
CREATE TABLE [dbo].[PARAMEXAMPLE](
[Entity] [varchar](16) NULL,

[Code]....

View 4 Replies View Related

SQL Server 2008 :: How To Append Hostname / Computername To Text File Using Windows Batch Command

Mar 9, 2015

How to append an hostname/computername to a text file using windows batch command?

View 1 Replies View Related

SQL Server 2008 :: Append Column Value In Server

Jan 29, 2015

How to append Column value in SQL Server 2008 R2.

I tried through CONCAT function, but it doesn't works.

View 1 Replies View Related

SQL Server 2008 :: Parent Records Ordering And Display Child Records Next To It?

Sep 7, 2015

declare @table table (
ParentID INT,
ChildID INT,
Value float
)
INSERT INTO @table
SELECT 1,1,1.2

[code]....

This case ParentID - Child 1 ,1 & 2,2 and 3,3 records are called as parent where as null , 1 is child whoose parent is 1 similarly null,2 records are child whoose parent is 2 , .....

Now my requirement is to display parent records with value ascending and display next child records to the corresponding parent and parent records are sorted ascending

--Final output should be

PatentID ChildID VALUE
33 1.12
null3 56.7
null3 43.6
11 1.2
null1 4.8
null1 4.6
22 1.8
null1 1.4

View 2 Replies View Related

How To Append Only New Records

Sep 15, 2006

What would be the steps to create a SSIS job to append records from an ODBC table to a SQL table, adding only the records from the source that do not already exist in the destination?

I have another post on this subject, with a good suggestion for the approach, but I need some more detailed instructions for implementing it:

Have you considered to use a Lookup task in your data flow to check if the row already exists in the destination table and then use the error output (no matches) for inserting only non existing rows? Notice that the error output of the lookup task needs to be set as 'redirect rows' in order to get this behavior

View 4 Replies View Related

How To Append Records Of One Table To Another?

Oct 11, 2004

Hi I have a table with the following structure:

Table1
-------
Dept
Filed1
Filed2
Field3
Field4
Field5

I have another table with the following structure
(Basically this table will contain a subset of coloumns of Table1)

Table2
-------
Dept
Field1
Field2

Now using a query I would like see all the records with all coloumns in Table1 plus all the records in Table2 appended

i.e
if Table1 row is

IT F1 F2 F3 F4 F5

and if Table2 row is

IT F11 F22
Sales F12 F23

I would like to see a result set with the following structure

Resultset

IT F1 F2 F3 F4 F5
IT F11 F22 NULL NULL NULL
Sales F12 F23 NULL NULL NULL

Can some body explain me how to do this with a query. I tried using union but it requires identical coloumns on both ends( Ofcourse, we can acheive this by having Field3,Field4 and Field5 as blank columns in Table 2 but I don't wanna do that as my original tables are too huge to handle this).

Any input is appreciated.

Thanks,
Sai

View 1 Replies View Related

How To Append The Records Of One View To Another?

Dec 5, 2007

Hi, I have two view (Run1OnlyFailures and Run2OnlyFailures). THey share exact same columes. Run1OnlyFailures has three records and Run2OnlyFailures has 5 records. Is there any way that I could put all 8 (3+5) records into a third view BothRunFailures, which share the same columns defination as Run1OnlyFailures and Run2OnlyFailures?

Thx
Tao

View 1 Replies View Related

Append Only Unique Records In SQL Table

Nov 23, 2007

I have a stored procedure that appends data from a temp table to a destination table.  The procedure is called from an aspx web page. The destination table has an index on certain fields so as to not allow duplicates.
The issue I'm having is if the imported data contains some records that are unique and some that would be duplicate, the procedure stops and no records are appended. How can I have this procedure complete it's run, passing over the duplicates and appending the unique records? Since the data is in a temp table (which gets deleted after each append) should I run some sort of 'find duplicates' query, and delete the duplicates from the temp table first, then append to the destination table?
Thanks in advance.SMc

View 2 Replies View Related

Empty A Table Before Using DTS To Append Records?

Jul 20, 2005

In Access I have a macro that, each night, takes a table with aprimary key defined in it, and deletes all the rows. Then itimports/appends records from a fixed width text file. In this way,since the table is not deleted and recreated, the primary key is keptintact.What would be the equivalent SQL method for doing this in an automatedway? I've tried letting DTS import the table from Access, but theprimary key is lost. Is there some way to "empty" a table instead ofdropping it, and then append new records so that the table will end uphaving the primary key I want it to have?Thanks.Larry- - - - - - - - - - - - - - - - - -"Forget it, Jake. It's Chinatown."

View 4 Replies View Related

Append New Records From ODBC Source

Sep 10, 2006

I have created a data warehouse that pulls information from an ODBC source into a SQL database. The schema in the destination matches the source, and the packages clear the destination tables, then append all the records from the source. This is simpler than updating, appending new, and deleting on each table to get them in sync since there is no modify timestamp in the source.

There are cases where I just want to append records from the source table that do not already exist in the destination table, without clearing the destination table first.

How can this be done with a SSIS job? Also, how can the job be run from a Windows Forms application?

View 4 Replies View Related

Using SQL To Append Records To A Table From A Flat File Using DTS

Aug 4, 2006

What I would LIKE to do is noted in the subject line. What I'm findingis that "edit SQL" appears to only be an option if I am creating atable. If I select "append to" the option to edit SQL shades itself asunavailable.The reason I'd like this is that there is a datum in the flat file thatindicates whether that record should be appended to that table notedabove. There are other ways of dealing with this "problem" but it wouldbe nice to be able to control it using SQL, in the DTS import/exportwizard.If the source of my data is an SQL table, I can generate an SQL queryto specify what fields to import in an append, to check for existingvalues, etc...Is there a way around this? I can reserve a table for data transfers,regularly overwrite it with new data from text file inputs, and use SQLto insert select fields from that transfer table to other databasetables. (From this "transfer" table, data needs to be inserted intofour separate tables in our database).I hope this is clear. If it CAN'T be done this way, it's okay...just alittle ugly with the need to re-create the transfer table.

View 3 Replies View Related

SQL Server 2008 :: Slow Row Number Over Partition

Jul 28, 2015

I have a simple table with 4 columns

(idAuxiliarPF(BIGINT+PK), pf(BIGINT+FK), Data(DateTime), Descr(NVARCHAR))that has aprox. 50k rows.

I need to create a partition of the data to join to another table, the query that i have:

SELECT
ROW_NUMBER() OVER (PARTITION BY pf ORDER BY Data DESC, idAuxiliarPF DESC) AS RN,
pf,
Data,
Descr
FROM dbo.PFAuxiliar
WHERE Data <= GETDATE()This query takes around 40 seconds to return the results

If i remove the Descr column, the query it takes no time.

SELECT
ROW_NUMBER() OVER (PARTITION BY pf ORDER BY Data DESC, idAuxiliarPF DESC) AS RN,
pf,
Data
FROM dbo.PFAuxiliar
WHERE Data <= GETDATE()I have two indexes, Clustered (idAuxiliarPF), NONClustered(pf).

How can i improve the performance of this query?

View 9 Replies View Related

SQL Server 2008 :: Calculate Number Of Days

Oct 8, 2015

I have client table which has client_id Eff_from and Eff_to columns.Eff_from and Eff_to are the dates that client is eligible for service. I need to know the average number of days from the day that he became not eligible and new eligibility date .

CLIENT_IDEFF_FREFF_TO
1001 12/24/200712/8/2010
100112/13/20123/26/2013
1001 5/27/20138/2/2013
10019/24/201310/30/2016

for expl days between
12/8/2010 and 12/13/2012
3/26/2013 and 5/27/2013
8/2/2013 and 9/24/2013

then AVG them.

View 3 Replies View Related

SQL Server 2008 :: How To Get Records In One Row

Apr 15, 2015

IdIncident IDIncident Description

2853459140511
2861733118512
2861733118601
2869113140511
2872349118512
2872349118601
2895400140511
2900999140511
2914574140511
2923590140511
2925735274503
2925735274504
2925735274511

View 9 Replies View Related

SQL Server 2008 :: Restore Number Of Databases Using Powershell

Aug 15, 2012

I have a new problem with doing a restore of a number of databases using powershell. The script I'm using is based mainly on this one (Part 2 in particular): [URL] .....

The problem I'm having is around the RedgateGetDatabaseName function. My hunch is that its down to the different version of red gate and how sqlbackup works. Basically when the call is made to the function it is returning both the Database Name and the number of row's that the SQL command in the function has ran. I've tried to include a SET NOCOUNT ON at the start of the SQL command in the function but its still returning the now count.

View 5 Replies View Related

SQL Server 2008 :: Select Alternate Number Of Rows?

Jan 28, 2015

A simple Query to select alternate rows from a table ?

View 9 Replies View Related

SQL Server 2008 :: How To Get Output Based On Sequential Number

Feb 13, 2015

The below data come from table table1. Instead of below result Ex1: I need output similar to the ex2.

Ex1:

CaseNumberStart CaseNumberEndExported
15000013150000131
15000014150000141
15000504150005041
15000505150005051

Ex2:

CaseNumberStart CaseNumberEndExported
15000013150000142
15000504150005052

How to get the result similar to Ex2, instead of Ex1. (ie., case-number is in sequential order then no need to break), And it should suit large dataset, I will finetune, if any performance issue.

View 1 Replies View Related

SQL Server 2008 :: How To Check Page Split Number

May 11, 2015

I am working now on optimization of an update query for a particular table and I want to measure the number of page splits after each update. How to check it?

View 6 Replies View Related

SQL Server 2008 :: Copying ID Number To Another Field In Table

Jun 26, 2015

I need to have a table that has a primary key

CREATE TABLE [dbo].[testing](
[tid] [int] IDENTITY(1,1) NOT NULL,
[sometext] [varchar](150) NOT NULL,
[idcopied] [varchar](50) NULL,
CONSTRAINT [testing_PrimaryKey] PRIMARY KEY CLUSTERED

..and eveytime I add 'sometext' as another row, the tid # needs to be duplicated to idcopied field

insert into [testing] (sometext,idcopied) values ('some junk',@@identity)

???

View 4 Replies View Related

SQL Server 2008 :: Maximum Number Of Sessions Has Been Reached

Jun 29, 2015

We have a big software that run a warehouse distribution center, written in .NET Backhand is a SQL Server 2008 R2 STD database.

Now, it seems there is a problem with the sessions not being properly closed after each call to the DB. Here is the message got form SQL:

DESCRIPTION:A new connection was rejected because the maximum number of connections on session ID 57 has been reached. Close an existing connection on this session and retry.

In the .NET code, connection is made with the following code:

If oConn Is Nothing Then oConn = New SqlConnection
If oConn.State = ConnectionState.Open Then oConn.Close()
With oConn
.ConnectionString = "Server=" & Server & ";Database=" & DB & ";User ID=" & User & ";Password=" & Pass & ";Connection Timeout=" & 5 & ";MultipleActiveResultSets=" & True
.Open()
End With

This code is called once, at the opening of the software

StoredProc are call with the code:
Try
oCmd = New SqlCommand
With oCmd
.Connection = oConn
.CommandType = CommandType.StoredProcedure

[Code] .....

So every Command is closed after execution, yet, they stay active in the SQL Server. Is there something I'm missing here?

View 3 Replies View Related

SQL Server 2008 :: Update The Document Number Row For 3k Rows?

Aug 4, 2015

I have a table where I would like to update the document number row for 3k rows. The problem I have is that the documents come in sets of two (version 1 and 2) but both have different numbers. Picture it like this below:

DOCNUM: 4445787 Version 1
DOCNUM: 4445790 Version 2

It should be the same docnum (ie 4445787 Version 1, 4445787 Version 2).

The challenge is how can we assign the new docnum for version 1 to be also for version 2 as well. Basically in SQL we need a way to

1. Find a way to distinguish the pair of documents in the target db that are the same even though they have different docnums.

2. Update them so that the docnums match.

View 7 Replies View Related

SQL Server 2008 :: Get Total Number Of Attachments Of Group ID

Sep 10, 2015

Copy and paste the code to review sample:

Create table #temp(
ID varchar (20),
ID_BegAttach varchar (20),
ID_EndAttach varchar (20),
ID_AttachLvl varchar (20),
ID_NumofAttach varchar (20)

[Code] ...

I'd like to get the column ID_NumofAttach to be populated by the total number of ID_Attachlevel column by the same ID_BegAttach or ID_EndAttach and populate where ID_Attachlevel is 0.

View 9 Replies View Related

SQL Server 2008 :: Multiple Records On One Row

Aug 20, 2015

I have a table of customer sales (dbo].[CustomerSales] which has a complete record od sales of our products for the past 5 years. I would like to create a report that extracts all the sales per customer on one row ie [CustomerID] 00011 has had 25 sales in the past 5 years and I would like to have their sales from left to right (starting with their earliest sale date at the beginning [SaleDate] field on the one row. I would also like to include the store location field [Location] along with the date the sale took place. So in other words the extract would look something like:

[CustomerID], [SaleDate], [Location], [SaleDate], [Location], [SaleDate], [Location], [SaleDate], [Location], [SaleDate], [Location], etc etc

Obviously some customers will have had less sales than others in which case I’m assuming these fields would just contain NULL values.

View 4 Replies View Related

SQL Server 2008 :: How To Result Query With Repeat Sequence Number

Mar 5, 2015

I want to make a query with the result like this, where Seqno is the result query which has repeating sequence number for same Field1

Field1Field2SeqNo
BVFUSBVFUS011
BVFUSBVFUS021
BVFUSBVFUS031
BVFRPBVFRP012
BVFRPBVFRP022

[Code] ....

I want the result also no ordered by Field1. it just as the natural order of the table..

View 3 Replies View Related

SQL Server 2008 :: Auto-Incremented Number Series To A Block

Mar 18, 2015

I want to assign consecutive numbers to a block of data, where block of data is based on days consecutive to each other i.e., one day apart.

Date format is: YYYY-MM-DD

Data:
TestId TestDate
----------- -----------------------
1 2011-07-21 00:00:00.000
1 2011-07-22 00:00:00.000
1 2011-07-27 00:00:00.000
1 2011-07-29 00:00:00.000
1 2011-07-30 00:00:00.000

[Code] ....

My Attempt:
WITH cte AS
(
SELECTTestId,
TestDate,
ROW_NUMBER() OVER(
PARTITION BYTestId

[Code] ....

Expected Output:
TestId TestDate OrderId
----------- ----------------------- --------------------
1 2011-07-21 00:00:00.000 1
1 2011-07-22 00:00:00.000 1
1 2011-07-27 00:00:00.000 2
1 2011-07-29 00:00:00.000 3

[Code] ....

The OrderId is the column I am trying to obtain using my following cte code, but I can't work around it.

View 0 Replies View Related

SQL Server 2008 :: Generate Increment Number With Conditional Restart

May 22, 2015

I need to create a script that adds an incrementing suffix to two columns, but restarts based on the value of another column. I found a similar question in the SQL Server 2000 forum, but it doesn't quite fit and also I'm working with SQL Server 2008 R2. The code below both creates a table with test data and tries to carry out the task. If you run this, you will see that the VISITNUM column has a value of UNS in row 4, UNS.1 in row 5 and UNS.2 in row 6. In row 7 it's V200, then in rows 8 and 9 it's UNS.3 for both. The same suffix gets applied to the VISIT column, but of course if I can solve this for VISITNUM then adding the suffix to VIST as well will be easy.

What I need is for row 8 to have UNS and row 9 to have UNS.1. In other words, any time the VISITNUM is UNS several times in a row, I need to add that ".X" suffix, but if a row has something other than UNS, I need to start over again the next time it's UNS again.

CREATE TABLE #testing(
KitID varchar(20),
SubjID varchar(20),
VISIT varchar(60),
VISITNUM varchar(20),

[code]....

View 8 Replies View Related

SQL Server 2008 :: Relation Between Max Degree Of Parallelism And Number Of CPU Cores

Jun 12, 2015

I have got a question on max degree of parallelism and CPU cores.

If max degree of parallelism = 1, this signifies that sql will use serial execution plan (unless u change it in query level with MAXDOP hint). In serial plan, will the query use all CPU cores (say in my server I have 16 core processors)?

If in serial execution plan only one thread works, then what the other threads doing ? Idle (I may have a defined max server worker thread = 32767(by default)

Unable to create a relationship between this parameters.

View 3 Replies View Related

How To Enter More Number Of Rows In A Table Having More Number Of Columns At A Time

Sep 24, 2007

Hi

I want to enter rows into a table having more number of columns

For example : I have one employee table having columns (name ,address,salary etc )
then, how can i enter 100 employees data at a time ?

Suppose i am having my data in .txt file (or ) in .xls

( SQL Server 2005)

View 1 Replies View Related

SQL Server 2012 :: Get Only Records Which Row-number Is 0 Or 1 In Module 20?

Mar 5, 2015

With this query i get only the records i need, but i would like to output in this way

1 - 20
21 - 30
31 - 40

of course in the real environment the ID are not consecutive, this is just one example of data.

declare @temp table (ID int)
declare @i int = 1
while(@i<1000) begin
insert into @temp values (@i)
set @i=@i+1
end
select ID from (
select ID, row_number() over (order by ID)
as rn
from @temp
) q where (rn % 20=0) OR (rn % 20=1)

View 3 Replies View Related







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