SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Data transfer while dynamic increment of duplicate values.


Data transfer while dynamic increment of duplicate values.

Author
Message
Lowell
Lowell
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28449 Visits: 39963
i f he's inserting into a constraint, and one of the new generated values happens to be the same as an existing value, i'd expect an error;
for example, just based on the RO time, data like the item exemplified below would generate two rows withtr he smae time, which might violate the constraint.

2013-05-07 15:09:00.00
2013-05-07 15:09:00.00 <-- this would generate 2013-05-07 15:10:00.00, a duplicate value
2013-05-07 15:10:00.00



Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Lynn Pettis
Lynn Pettis
SSC-Dedicated
SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)

Group: General Forum Members
Points: 39836 Visits: 38563
With nothing to do any testing with, give this a try:



WITH BaseData(
Class,
Date_Entered,
PMmiles,
RO,
RoDate,
Time_In,
Ranking
)AS(
SELECT --RO,Time_In, Ranking = DENSE_RANK() OVER (PARTITION BY RO,Time_In ORDER BY NEWID() ASC)
Class,
Date_Entered,
PMmiles,
RO,
RoDate,
Time_In,
Ranking = row_number() over (partition by RO, RoDate, Time_In order by (select null))
FROM
DTAGatHERTZ_RO
)
INSERT INTO ROs
SELECT
Class,
Date_Entered,
PMmiles,
RO,
RoDate,
DATEADD(mi,Ranking - 1, Time_In
from
BaseData
where
RO = '4187';




Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Neeraj Dwivedi
Neeraj Dwivedi
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1101 Visits: 1336
Lowell, he has mentioned in first post that The primary key combination for the destination table is "ROBumber + ROTime" .
Lowell
Lowell
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28449 Visits: 39963
Neeraj Dwivedi (5/7/2013)
Lowell, he has mentioned in first post that The primary key combination for the destination table is "ROBumber + ROTime" .


agreed, but if he auto generates an overlapping value ,"ROBumber + ROTime" + 1 in the case of duplicate "ROBumber + ROTime" from the source, he of course could duplicate the value, but against a different row than was incremented.

that was my point...he's not guaranteeing a PK value is unique with the current logic of arbitrarily incrementing a value.

Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Prasune Verma
Prasune Verma
SSC Rookie
SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)

Group: General Forum Members
Points: 36 Visits: 74
Thanks Neeraj, It was my lack of pre-knowledge on CTE which was preventing me to interpret your suggested solution correctly. I googled about CTE and then came back to apply what you were trying to suggest and it has worked perfectly.

Many thanks for your valuable time and solutions. Thank you all for the suggestons. Very much appreciative and supportive.

Thanks and Regards,
Prasune Verma.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search