Ok basically iam using a cursor to scroll thru the record set, and change the primary key to prefix a 'X char on the front. I do this by stripping off the first 3 chars, and then taking the last 11 and thus provide space for the 'X'.
I need to update this key i.e new_code=old_code where something? = something? problem is all the other fields can be null. so what do i do?
do i need an index temp table or something?
*However I dont think this is the best way so I would like some guidance as to the best approach.
declare @Code varchar(15)
declare @Int_EntityCode varchar(15)
declare @EntityCode varchar(15)
declare @added_prefix_entity_code varchar(15)
declare @prefix_entity_code varchar(15)
declare @suffix_entity_code varchar(15)
select @Int_EntityCode = '000000000000000'
select @prefix_entity_code = ' '
select @suffix_entity_code = '0'
select @added_prefix_entity_code = 'X'
declare @zerofill int
select @zerofill = '0'
DECLARE CUR_Multi_Insert SCROLL CURSOR FOR
SELECT Code
FROM entities
OPEN CUR_Multi_Insert
FETCH NEXT FROM CUR_Multi_Insert
INTO @Code
while @@fetch_status = 0
BEGIN
--Entity Code Construction
select @entitycode = @code
print @entitycode
select @prefix_entity_code = left (@Code,3)
print @prefix_entity_code
select @suffix_entity_code = right (@Code,11)
print @suffix_entity_code
select @EntityCode = @added_prefix_entity_code+@prefix_entity_code+@suffix_entity_code
print @EntityCode
FETCH NEXT FROM CUR_Multi_Insert
INTO @code
END
CLOSE CUR_Multi_Insert
DEALLOCATE CUR_Multi_Insert
I need to update this key i.e new_code=old_code where something? = something? problem is all the other fields can be null. so what do i do?
do i need an index temp table or something?
*However I dont think this is the best way so I would like some guidance as to the best approach.
declare @Code varchar(15)
declare @Int_EntityCode varchar(15)
declare @EntityCode varchar(15)
declare @added_prefix_entity_code varchar(15)
declare @prefix_entity_code varchar(15)
declare @suffix_entity_code varchar(15)
select @Int_EntityCode = '000000000000000'
select @prefix_entity_code = ' '
select @suffix_entity_code = '0'
select @added_prefix_entity_code = 'X'
declare @zerofill int
select @zerofill = '0'
DECLARE CUR_Multi_Insert SCROLL CURSOR FOR
SELECT Code
FROM entities
OPEN CUR_Multi_Insert
FETCH NEXT FROM CUR_Multi_Insert
INTO @Code
while @@fetch_status = 0
BEGIN
--Entity Code Construction
select @entitycode = @code
print @entitycode
select @prefix_entity_code = left (@Code,3)
print @prefix_entity_code
select @suffix_entity_code = right (@Code,11)
print @suffix_entity_code
select @EntityCode = @added_prefix_entity_code+@prefix_entity_code+@suffix_entity_code
print @EntityCode
FETCH NEXT FROM CUR_Multi_Insert
INTO @code
END
CLOSE CUR_Multi_Insert
DEALLOCATE CUR_Multi_Insert