[Show all top banners]

U?Me
Replies to this thread:

More by U?Me
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 SQL Automatic incremental generator

[Please view other pages to see the rest of the postings. Total posts: 32]
PAGE: <<  1 2  
[VIEWED 10686 TIMES]
SAVE! for ease of future access.
The postings in this thread span 2 pages, View Last 20 replies.
Posted on 06-04-08 7:10 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Hi All:
I have a column in a table with datatype varchar(60). I need to start inserting values into this column (starting sequentially from R000001 onwards). So, the next record would be R000002, so on and so forth. I tried using NewID() function, however this generates unique hexadecimal numbers like 019D9F4F-E16C-4EDF-9E02-DF1190B7AECF

Any help is greatly appreciated
 
Posted on 06-06-08 4:02 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

again proble??

just kidding dude . actually am going out of desk now.going home now. i will see once i get into appt.


 
Posted on 06-06-08 4:12 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Rawbee,
I know right! I solved the problem.......And btw im a girl errmmmmm...lady actually so be nice j/k.

Everyone,
I am not an expert in SQL. I know it well but everyone runs into a new problem, right?

Another problem, I am trying to
insert into another live Table C, a value CompanyCode. When I do,

select
Customer.company_code

from Table B
left outer join TableC Customer on......

where ....
I get this error:
Msg 2601, Level 14, State 3, Procedure InsertCicmpy1stNotice, Line 11
Cannot insert duplicate key row in object 'Table C with unique index 'AccountCode'.
The statement has been terminated.

I dont know where this AccountCode is from?? Thanks!!


 
Posted on 06-06-08 4:13 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Rawbee,
I know right! I solved the problem.......And btw im a girl errmmmmm...lady actually so be nice j/k.

Everyone,
I am not an expert in SQL. I know it well but everyone runs into a new problem, right?

Another problem, I am trying to
insert into another live Table C, a value CompanyCode. When I do,

select
Customer.company_code

from Table B
left outer join TableC Customer on......

where ....
I get this error:
Msg 2601, Level 14, State 3, Procedure InsertCicmpy1stNotice, Line 11
Cannot insert duplicate key row in object 'Table C with unique index 'AccountCode'.
The statement has been terminated.

I dont know where this AccountCode is from?? Thanks!!


 
Posted on 06-06-08 6:35 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 
 
Posted on 06-09-08 11:07 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Maybe 'Accountcode' is an Index ........check index and make twist as needed..

tips: disable the index and see if it works...just to make sure its an index problem and take it from there.

Good Luck


 
Posted on 06-09-08 11:23 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Hi,

Yes, AccountCode is a unique non-clustered index:

 

When I insert the data into Live Table A, all other fields but this(Represented by Account) will be displayed o because it is derived from this unique non-clustered index.

I tried to do an insertion on Table B (where the Account # is), but I got this error:

 

Msg 2601, Level 14, State 3, Line 1

Cannot insert duplicate key row in object ''B'with unique index 'AccountCode'.

The statement has been terminated.

 

(0 row(s) affected)

 

Now, There is a column in both Table A and Table B. Insertion in Table A works, but how do I update that value in Table B.?

Thanks in Advance!

 



 
Posted on 06-09-08 12:59 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

First, Do you really want duplicate values on Table B. If yes why do  you have unique index. Simply drop the index and you should be fine.

Secondly, Wat kinda value do you want in Table B. Are you trying to insert from table A.

Can you be more specific on the value you want on table B and why are you inserting duplicate values and how do you want that to be handled.


 
Posted on 06-09-08 1:25 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Ok here is the deal.
There is this intranet website.

I basically have to create an automatic process of sending out the Renewal Notices when the customer’s subscription is about to expire.


There is a live table A with Customer Account information. There is another live Table B with customer shipping, ID, etc.  I had to gather a list of customers whose subscription ends in a certain date range and change their NoticeStatus to '1stNotice'...etc

 

I had to create a table C with all CustomerAccountInfo (from live table A) where subscription ends in 2 months from now. After that I update their renewal status to ‘1st Notice’ .

 

Then on the main Live table A , I append all these records I just generated from table C, also doing case when ….statements.

Now, all the fields in the intranet gets uploaded automatically, besides one field Subscriber.

This subscriber field is apparently generated from unique non-clustered index in live Table B. I cannot change the structure of that table.

Table B holds CustomerPersonalInformation including a column cmp_code is the company code which needs to be put in the field Subscriber.

 

So after I insert into Table A, I tried updating Table B, using :

update cicmpy –this is the table B in my description

set cmp_code = (

select

enduser.cmp_code as Subscriber

 

from

RenewalLetter r –this is the table C in my description

left outer join cicmpy Subscriber on freeguidfield_01 = Subscriber.cmp_wwn

left outer join cicmpy Enduser on CustomerID = Enduser.cmp_wwn

 

where

type = 75

and ltrim(freetextfield_10) = 'Active'

and freedatefield_01 between

dateadd(mm,2,getdate())

AND dateadd(mm,2,getdate())+7

 

and freeboolfield_05 not like '1'

and subscriber.classificationid in ( 'HMO', 'EUR'))

 

And I get this error I explained in the previous post.




 
Posted on 06-09-08 2:59 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Certainly Its a very very complicated select statment,..

Wondering if it is possible to avoid the outer join with cicmpy enduser after the outerjoin between renewlletter and the cicmpy subscriber...it gets to complicated.

Also, i bet you have check the result of your select stattement.. can you check it again and make sure that the select statement is giving you more than one null in result. As more than one Null would violate the unique constraint.

Try doing this in your test server and see if it works

CREATE UNIQUE INDEX accountcode ON cicmpy (subscriber)
    WITH (IGNORE_DUP_KEY = ON);

PS: Remember its Monday, stressful day for most of us.

Last edited: 09-Jun-08 03:02 PM
Last edited: 09-Jun-08 03:04 PM

 
Posted on 06-09-08 3:00 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

duplicate post

Last edited: 09-Jun-08 03:03 PM

 
Posted on 06-09-08 5:15 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Hey Arnzombie ,
Thanks for your continuous help. I called a meeting to try to understand and solve this issue. On the other hand, let's go back to the original problem I posted (hence the start of this thread). I created this function:

alter function NextCustomerNumber (@id int)
returns char(7)
as
begin
return 'R' + right('000000' + convert(varchar(10), @id), 6)
end

Now, the problem I have is, the number starts wherever it pleases. Instead of starting at C00001, and auto-incrementing by 1, this is just too random. any suggestions?

 
Posted on 06-10-08 8:35 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Its my pleasure, anyways why dnt  you get the highest id number in this case or pass the highest id number as parameter...

alter function NextCustomerNumber

returns char(7)
as
begin

set @id = select max(ID) from table_name ;--to get the highest id number from the table
return 'R' + right('000000' + convert(varchar(10), @id), 6)
end;

----------------------------------------------------------------------------------------------

OR

begin

set @id = select max(ID) from table_name ;--

select NextCustomerNumber(@id) ....

END;

 

 


 



PAGE: <<  1 2  
Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 200 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration case still pending ..
Anybody gotten the TPS EAD extension alert notice (i797) thing? online or via post?
TPS EAD auto extended to June 2025 or just TPS?
Toilet paper or water?
ढ्याउ गर्दा दसैँको खसी गनाउच
Mamta kafle bhatt is still missing
ChatSansar.com Naya Nepal Chat
whats wrong living with your parents ?
I hope all the fake Nepali refugee get deported
TPS advance parole Travel document i-131, Class of Admission ?
Tourist Visa - Seeking Suggestions and Guidance
Now Trump is a convicted criminal .
Ajay Kumar Dev sentenced to 378 yrs
Biden said he will issue new Employment visa for someone with college degree and job offers
Why Americans reverse park?
Problems of Nepalese students in US
Nepali Passport Renewal
lost $3500 on penny stocks !!!
Biden out, Trump next president, so what’s gonna happen to TPS, termination?
They are openly permitting undocumented immigrants to participate in federal elections in Arizona now.
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters