Transact SQL :: Getting Sequence Data

Oct 27, 2015

Please find the necessary SQL to create the table with sample data down below.In this simple table, I'm keeping project status logs i.e. what project, what happened and when.I want to create a select statement that will give me the ProjectId and the time stamps from "Contract Signed" to "First Meeting". So, I'd like my data to look like this:

ProjectId - FromStatus - FromTimeStamp - ToStatus - ToTimeStamp
123  - 'Contract Signed' - 6/21/2015 3:33PM - 'First Meeting' - 6/27/2015 8:45AM
456  - 'Contract Signed' - 6/25/2015 9:00AM - 'First Meeting' - 6/29/2015 2:50PM
987  - 'Contract Signed' - 9/29/2015 11:00AM - 'First Meeting' - 7/11/2015 10:00AM

Please notice that in my SELECT statement, I don't want to see anything else. For example, I don't want ProjectId: 555 included because it never made it to "First Meeting". I also don't want to see any information about "Press Release" for ProjectId: 123. I only want to see those projects that went from "Contract Signed" to "First Meeting".

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[ProjectStatus](
[LogId] [int] NOT NULL,

[code]...

View 3 Replies


ADVERTISEMENT

Transact SQL :: How To Change Auto-sequence Numbers To Match Sorted Data

Jun 15, 2015

I have a database that has entries that I want sorted by date order. Each entry has an auto ID number allocated (primary key auto sequencing), which I want to change to reflect the sorting (so the first date has the first auto ID number and so on).I've gone into the database and sorted the entries as I want them. Then I've gone into Design View to delete and restablish the primary key autosequence. However, it is not keeping the date order in the database (ie entry ID 3140 date is 12/06/2015, but 3141 is 02/02/2012). How do I get it to maintain the order?

View 3 Replies View Related

Transact SQL :: Getting A Sequence Pattern?

Apr 30, 2015

I need a simple tSQL code that will produce an array sequence values that has gap with 2 or more consecutive values, which can vary - so 2 or 3 or 4 between sequence of number.  For example, I want it to return a series with a  gap or space of 2-  So it should return 1, 2, 5, 6, 9, 10.. or a gap of 3 -  1,2 ,6,7,11,12.. etc I  know a single gap is quite simple using a recursive cte, but I haven't been able to find how to get this kind of result.

View 14 Replies View Related

Transact SQL :: Server Identity Or A Self Calculated Sequence

Jun 14, 2015

I am designing a database. I want to define a automatic sequence  on a table primary key field. what is the best solution for it?I know I can enable identity property for a field, but  it has some problems ( for example its seed jumps on restart and unsuccessful events).I also can use some calculated sequences. for example I can calculate max of the filed values and after incrementing use it as key for new inserted record.

View 4 Replies View Related

Transact SQL :: Sequence Of Characters - Extract Some Specific Values

May 13, 2015

I've the following data:

<Hour>11</Hour><Hour>12</Hour><Hour>15</Hour><Hour>18</Hour>

And my goals is to the extract the following example:

11,12, 15, 18

How Can I do That?

View 6 Replies View Related

Transact SQL :: Insert Rows Into A Table For Missing Sequence Numbers

Jul 29, 2015

In a t-sql 2012 sql update script listed below, it only works for a few records since the value of TST.dbo.LockCombination.seq only contains the value of 1 in most cases. Basically for every join listed below, there should be 5 records where each record has a distinct seq value of 1, 2, 3, 4, and 5. Thus my goal is to determine how to add the missing rows to the TST.dbo.LockCombination where there are no rows for seq values of between 2 to 5. I would like to know how to insert the missing rows and then do the following update statement. Thus can you show me the sql on how to add the rows for at least one of the missing sequence numbers?

UPDATE LKC
SET LKC.combo = lockCombo2
FROM [LockerPopulation] A
JOIN TST.dbo.School SCH ON A.schoolnumber = SCH.type
JOIN TST.dbo.Locker LKR ON SCH.schoolID = LKR.schoolID AND A.lockerNumber = LKR.number

[Code] ....

View 10 Replies View Related

Data Sequence In Tables, Please Help

Jul 8, 2007

I'm new to sql server 2005. Previously I used Access. I've noticed that in sql server when a record is inserted into the database table, the data does not get entered sequentially. I looked at the id column and saw that the order numbers are mixed up. Is this something that is common in sql server, and how can I change this. I need the data to be ordered in the order that it was inserted into the database.



Can someone please help.

View 3 Replies View Related

Add Sequence Number To Data

Sep 17, 2007



Hi all, I need some your help.
I want to add sequence number to data flow below:

Cust_Name | Month
=======================
Chonnathan | 5
Chonnathan | 4
Chonnathan | 7
Derec | 3
Derec | 9

and the result i need is:

SEQ_nbr | Cust_Name | Month
================================
1 | Chonnathan | 4
2 | Chonnathan | 5
3 | Chonnathan | 7
1 | Derec | 3
2 | Derec | 9

How can I do it in Integration Service to show like the above?

Thank you for your respones,
Chonnathan

View 1 Replies View Related

Data Bases For Sequence Clustering

Aug 24, 2007



hi

where i can find some data bases to see how the sequence clustering works?.

thanks a lot

View 1 Replies View Related

Sequence Execution At Data Flow Task ?

Apr 25, 2008



I have one Data flow, which trasfer data into two table (Parent & Child) .

My question is : Is there a way, i can load data first into parent and then child table. because child table getting load first after that parent table loading. (Execution should be Source Parent --> Destination Parent) First , (Source Child --> Destination Child) Second.
In my case its executing reverse. So i have foreign key constraints at child table , its giving foreign contraints error while running ssis package

Can any one tell me,
How to define my own sequence execution at the Data flow task (Source - Destination) ?

Thanks

View 3 Replies View Related

Select Data Horizontally - Max Sequence Number May Vary

Sep 8, 2012

I have the following table:

Policy Sequence LossDate Description Amt
123 1 9-1-2012 property 100
123 2 10-1-2012 property 200
345 1 9-1-2012 property 100
345 2 10-1-2012 property 100
678 1 9-1-2012 property 100

I want to select the data as follows:

Policy LossDate1 Description1 Amt1 LossDate2 Description2 Amt2
123 9-1-2012 property 100 10-1-2012 property 200
345 9-1-2012 property 100 10-1-2012 property 100
678 9-1-2012 property 100 NULL NULL NULL

Is there a way to do this using T-SQL?

The max sequence number can vary, so far the max has been 12, but may be higher in the future.

View 2 Replies View Related

SSIS Sequence Container,data Flow Task

Nov 28, 2005

I am creating a staging database in which I am loading required tables from 2 different sources.
I have 30 different tables to load from source 1 and 10 different tables from source 2.
This is the way I am doing, in Control flow task I am using Sequence container and in that I included the data flow task, the data flow task
has source OLD DB connection from where I select the table and then destination OLE DB connection where I load the data.
So for 30 tables I have one Sequence container with 30 different data flow task and each data flow task has OLE DB source and OLD DB destination.
I wanted to find out if this is the efficient way to do, or if there is any other way to do this.
And for source 2 shall I put in another package or shall I use the same package with different sequence container and follow the same steps
as for Source 1 tables.
Please advice.
Thanks,

View 19 Replies View Related

Data Mining :: Updating Two Columns With Sequence Numbers With Where Clause

Jun 29, 2015

I have a question  in SQL server. For example I have a table which has two column like following table and I don't know how can I update theses two column with identity numbers but just the fields which are equal 111.

Example table:
numez numhx
111 111
111 111
0 111
111 0
111 0

and my results should be:
numez numhx
1 2
3 4
0 5
6 0
7 0

View 3 Replies View Related

How To Append A New Values Like Uniqueidentifiers, Sequence Numbers To Data Flow?

May 9, 2006

Hi,

I would like to know different possible ways in appending extra values like new uniqueidentifiers, sequence numbers, random number. Can you please tell what type of data flow components helps us ?



View 5 Replies View Related

Transact SQL :: Key And Indexes On Two Column Data Table Or Parsed View (Large String Of Data And Filename)

Oct 4, 2015

I am studying indexes and keys. I have a table that has a fixed width of data to be loaded in the first column which is parsed in a view based on data types within the fixed width specifications.

Example column A:
(name phone house cost of house,zipcodecountystatecountry)
-a view will later split this large varchar string based 
column b: is the source filename of the data load (varchar 256)
....

a. would there be a benefit of adding a clustered or nonclustered index (if so which/point in direction on why)

b. is there benefit of making one of these two columns a primary key (millions of records) or for adding a 3rd new column as a pk?

c. view: this parses the data in column a so it ends up looking more like "name phone house cost of house zipcode county state country" each having their own column.

-any pros/cons of adding indexes (if so which) to the view instead of the tables or both for once the data is parsed?

View 4 Replies View Related

Transact SQL :: Excel Data Import Truncate Data Length To 255

Jul 29, 2015

I am trying to import data from an excel Sheet to SQL Database using OPENROWSET. After import I found that all the cells containing data of more than 2000 length got truncated to  255 characters only. I tried finding the solution and found that We need to have the data with length more than 255 in first 8 rows of Excel sheet. It worked for me also. But In real scenario the data that I cant do the manual work on excel. I tried out with Dot Net utility and SSIS package also but the truncation is still the issue.

INSERT into tmp_Test
SELECT
*
FROM
OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel
12.0;Database=D:Book1.xlsx', [Sheet1$])

View 9 Replies View Related

Transact SQL :: Table Row Data Show In Column Data

Oct 22, 2015

I have a simple table data i want want to show row data in to column data.
      
SELECT clblcode,mlblmsg
FROM warninglabels

My expected result will be 

0001                 0002  0003                      0004
-------                ------- --------                    --------
May Cause....       Important.....  Take madi...........         Do Not Take.......

View 16 Replies View Related

Transact SQL :: Need To Convert Multiples Rows Data To 1 Row Data

Nov 13, 2015

I need to create SQL to convert multiple rows data to single row for given subscriber#. Below is the example. In below example , I've 4 family members with same subscriber # and each members have separate rows, I want to combine member data for same subscriber in 1 row, so there would be a 1 row for each subscriber. 

View 6 Replies View Related

Transact SQL :: Filtering Out Data

Aug 31, 2015

I have a simple query

select distinct
 bl_rec_ref
 ,freq_cd
 from hgmprty1
where(bl_rec_ref is not null and bl_rec_ref not like '%SCH%')

That produces the following output (part shown)

However what I need to show is only bl_rec_ref values where there is no corresponding freq_cd of QTLY.

Looking at the example data above Rows 45 and 46 have the same bl_rec_ref value with a MTHLY and a QTLY value in freq_cd so therefore I don't want this to appear in my output. Similarly with Rows 47 and 48 were the bl_rec_ref has both QTLY and MTHLY values so again should be excluded.

However looking at Rows 51 to 55 which has a bl_rec_ref only showing once for each value of MTHLY and no value for QTLY so these Rows are required in the output.

View 4 Replies View Related

Transact SQL :: Get Max Date For Data Available For All IDs

Jul 19, 2015

I have a temp table

drop table #temp
create table #temp (id int, dat datetime)
insert into #temp values(1,'2015-03-01')
insert into #temp values (2,'2015-02-01')
insert into #temp values (2,'2015-01-01')
insert into #temp values (3,'2015-01-01')
insert into #temp values (3,'2015-03-01')
insert into #temp values (3,'2014-12-01')
insert into #temp values (2,'2014-12-01')
insert into #temp values (1,'2014-12-01')
select * from #temp

The result i am expecting is  2014-12-01. I need to get the max(dat) for data available for all ids.In the sample set, only for 2014-12-01, there is a row for id 1,2,3. I need to get that date as result. 

View 11 Replies View Related

Transact SQL :: Get Data For First And Last Date

Apr 23, 2015

I have a table that capture the size of databases every week.

CREATE TABLE [dbo].[DBGrowthRate](
 [DBGrowthID] [int] IDENTITY(1,1) NOT NULL,
 [DBName] [varchar](100) NULL,
 [DBID] [int] NULL,
 [CurSize] [decimal](10, 2) NULL,
 [Gatherdate] [datetime] NULL,
 [Serversname] [varchar](50) NULL
) ON [PRIMARY]

What I want is to make a query that will return

DBName, Cursize (oldest Gatherdate, CurSize (most recent GatherDate, ServersName

How to make this happen, I have tried working with Max and Min Gatherdate but that doesn't work.

View 7 Replies View Related

Transact SQL :: How To Transform Data

Jul 30, 2015

how I can transform this input (in SQL Server 2008 R2)

SiteID    EdateTime
L5500     2015-07-30 05:00:48.000
L5500     2015-07-29 05:00:49.000
To be…
SiteID    StartDate                                  EndDate
L5500     2015-07-29 05:00:49.000         2015-07-30 05:00:48.000

View 6 Replies View Related

Transact SQL :: Getting Data For Last 3 Months

Oct 14, 2015

I have a date into format YYYYMM. Data type is int. I need to make query where every time it will return me last 3 months, but without current one. For example I have data for months below

201510
201509
201508
201507

Query should return all records for 201509, 201508, 201507.

I was trying lot of solutions founded in internet like this one:

Date_Column >= DATEADD(MONTH, -3, GETDATE())
or
DATEDIFF(MONTH, my_date_column, GETDATE()) <= 3

but it doesn't work.

View 4 Replies View Related

Transact SQL :: How To Get Value Of A Particular Field From XML Data

Nov 6, 2015

We are running the following querry which insert data row from an XML source

INSERT INTO End_ReelProcessValue
(LineId
,ReelHist_id
,Variable_tagName
,ProcessMeasure
)

[Code] ....

From that querry, I need to store in a variable the Value of a particular XML entry in order to store it in an other table.The XML parsing is based on the following lines :

[Variable_Tagname] CHAR(50) '@Name',
[ProcessMeasure] NVARCHAR(254) '@Value'

What I need is that if the [Variable Tagname] issue from entry @Name is equal to the string "Quality", then I need to store its value to a variable.Then an other querry will use that variable to insert it to an other table.

How can I retrieve that particular record ?

View 2 Replies View Related

Transact SQL :: Reading XML Data

May 26, 2015

I have a table with a column  with data type XML.I dont know the contents of the XML structure etc and I need to extract it

View 5 Replies View Related

Transact SQL - Combining Two Columns Of Data

Oct 23, 2001

How do I combine two columns (ex: [first name] [last name]) to get a combined result in a new column of ([first name] [last name]).

Thank you,

Andrew

View 2 Replies View Related

Transact SQL :: Query For Yesterday Data

Dec 2, 2008

Howto write a query which will find the date from yesterday 12.00am till yesterday 11.59.59PM. that means yesterday 24 hrs only. If I use getdate it will show me the date which is right now which i don't want. everyday i need to search the data from yesterday whole day.

View 13 Replies View Related

Transact SQL :: How To Display Two Groups Of Data Across The Top

Nov 10, 2015

I have a Cost table with the following field:

Year, Quarter, Cost1, Cost2

I would like to write a SQL so that it will give me something like that, so that I will have 2 years across the top with the same same columns.

2016 
 
2015

Quarter
Cost1
Cost2
 
Cost1
Cost2

1
100
200

[code]....

View 3 Replies View Related

Transact SQL :: Transpose Data Update

Jul 15, 2015

I have following sample data

I want this data updated to different table based on PK value relationship like below,

What shall I do to make such update ? Here is the sample script I want ot use

 DECLARE @Activity TABLE(PK BIGINT,Value1 NVARCHAR(10),Value2 NVARCHAR(10))
 INSERT INTO @Activity(PK) VALUES(1)
 INSERT INTO @Activity(PK) VALUES(2)
 INSERT INTO @Activity(PK) VALUES(3)

[Code] .....

View 11 Replies View Related

Transact SQL :: Striping Data Into Two Columns

Jun 3, 2015

In SQL statement is it possible to split the below column into two columns?

COLUMN_AAAAA AAAAAAA CO A.A. # 4030
BBBBBB BBB BBB CO. # 4260
CCC CCCCC #3001

View 16 Replies View Related

Transact SQL :: Select Data In Pair?

Sep 22, 2015

my business user want all record where glcode must start with 2 and 4

<sample data

Tran_No 

GLCode

abcd123

2123

abcd123

21235

abcd123

4289

[code]....

View 6 Replies View Related

Transact SQL :: How To Get Max Date And All Rows Data

Oct 17, 2015

i have this table the TDate in string (not date)

MEN
===
id       |      Name    |      TDate
1        |   aa           |       01.05.2015
2        |   bb           |       05.05.2015

View 6 Replies View Related

Transact SQL :: Split Column Data To Row

May 19, 2015

I found string from net how to split column data to row

SELECT A.JbIDFull, A.ProdID, A.OrderQty, A.OtherDetails, A.OrderDate, c.Item FROM
(SELECT JbIDFull, DeptID, ProdID, OrderQty, OtherDetails, OrderDate, LamORSteachType, JBID, RMIDs, RMQty
FROM tblJobCardforProduction WHERE JBID = '2' AND DeptID = '3') A
CROSS APPLY dbo.SplitStringNEW(a.RMIDs,';') b
CROSS APPLY dbo.SplitStringNEW(a.RMQty,'/') c

When I apply one cross apply it's working fine but when i apply for one more column is replacing three time one row, this data i want to split RMIDs and RMQty with same JbIDFull

JbIDFull   DeptID    ProdID OrderQty     RMIDs RMQty

PD-May15-00001 3 2044 10000     PROD-00052 0
PD-May15-00002 3 921 1000 PROD-00052;PROD-00383;PROD-00384 500;600;700

View 2 Replies View Related







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