Update Column With Increasing Sequential Numbers

Feb 18, 2008

Here is my problem. I have a table with 4 columns id1,id2,id3,boxnum. Here is some sample data.

id1 id2 id3 boxnum
1 1 1

1 1 1
1 2 1
1 2 1
1 2 1
2 2 2
2 3 4

What I need is to be able to update boxnum with sequential numbers based on the unique set of values from the id columns. So my output would be this.


id1 id2 id3 boxnum
1 1 1 1

1 1 1 2
1 2 1 1
1 2 1 2
1 2 1 3
2 2 2 1
2 3 4 1

View 6 Replies


ADVERTISEMENT

I Need To Update A Table With Random Numbers Or Sequential Numbers

Mar 11, 2008



I have a table with a column ID of ContentID. The ID in that column is all NULLs. I need a way to change those nulls to a number. It does not matter what type of number it is as long as they are different. Can someone point me somewhere with a piece of T-SQL that I could use to do that. There are over 24000 rows so cursor change will not be very efficient.

Thanks for any help

View 6 Replies View Related

Sequential Numbers In Column

Oct 25, 2013

I have a table with 13,000 rows, in one column called Prioirty each row has a value of 1.

Is it possible to use SQL to replace all of these '1' values with a sequential list. Example 1,2,3,4,5,6,7....all the way to 13,000?

View 3 Replies View Related

Create Sequential Numbers In A Column

Jul 20, 2005

I have a temp table that's populated with an insert query in as toredprocedure. The temp table has a uniqueID as the primary key.In that table I have a column SortOrder.What I want to do is to create a sequential number in SortOrder butonly for records matching a WHERE statement, for example:(pardon the shorthand...)Insert *.tblPermanent into tblTempIf myField = 1 thenSortOrder = 1(2,3,4,5,.....etc.)elseSortOrder = 0Thankslq

View 1 Replies View Related

Simple Query To Create Column Of Sequential Numbers

May 2, 2006

Hi,
Can anyone tell me offhand the simplest/most elegant way of updating an integer column to a sequential column of numbers with a query?

e.g given

intval | Description| Cost
0 | Descvalue0| 4.32
2 | Descvalue2| 4.33
3 | Descvalue3| 4.34
8 | Descvalue8| 4.35

change it to:

intval | Description| Cost
0 | Descvalue0| 4.32
1 | Descvalue2| 4.33
2 | Descvalue3| 4.34
3 | Descvalue8| 4.35

I think it might need a stored proc..

Many Thanks
greg

View 2 Replies View Related

Query Help - Sequential Numbers

Apr 27, 1999

I have a query which returns information about transactions similar to this:

Select account, trans_code, quantity
from ledger_table

This returns something like:

acct trans_code quantity
----- ---------- ------------
2 2 1000
2 3 500
2 3 300
3 2 100
3 2 500
etc.

What I need to do is add a lot number for each acct/trans code type. This is merely a sequential number for the transaction. This changes the output as follows:

acct trans_code quantity lot
----- ---------- ------------ ---
2 2 1000 1
2 3 500 1
2 3 300 2
3 2 100 1
3 2 500 2
3 3 1000 3
3 5 200 1
etc.

The lot number is reset for each grouping.

Does anyone have a way to do this outside of a cursor or temp table?

TIA, any help greatly appreciated.

View 1 Replies View Related

Assign Sequential Numbers

Mar 17, 2004

I am trying to automatically insert records into my existing customer table. Is there a way when I insert these new records and assign the customer number that it can sequentially pick the next available unique customer number for each record that is inserted? for example the first record would be customer number 100, the next 101, and so on? Please advise.

View 4 Replies View Related

Generating Auto Sequential Numbers

Jul 23, 2005

I am using sybase aSE12.5. I have a table with only one column withdatatype char(2). when i query this table to select all the records, ishould get these records in the ascending order and they should be numbered, i.e, the o/p should look something like thiscolumn_name------ --------1 AB2 AC3 ADand so on.I cannot add an extra column and i need this to be done in a single query.--Message posted via http://www.sqlmonster.com

View 2 Replies View Related

Populating Empty Table With Sequential Numbers?

Jan 15, 2015

I have a column within a table which is already truncated/deleted all records within (Microsoft SQL 2008). I have to now populate the column with sequential numbers up to 50,000 records arbitrary numbers (doesn't mater) up to 7 characters.

what SQL statement I need to write that will automatically polulate the newly empty table with A000001,A0000002,A0000003, or any form for that matter etc so that I can sort number the records within the table.

I have approximately 50000 records which I need to sequentially entered and I really dont want to number the column manually via hand editing.

View 5 Replies View Related

SQL Query - Find Block Of Sequential Numbers

Jul 20, 2005

I have a database that is pre-populated with sequential part numbers.As people reserve the parts I update a flag to show the # is no longeravailable. Now they want the ability to take out a block of "x"number of sequential part numbers - say for example 5.If my database had the following numbers available:101104105110111112113114It should return 110 thru 114 and then I would write an update queryto change the flags to 1 (checked out).I have only been able to return the first "x" number of records - havenot been able to make sure they are stepped sequentially - with thefollowing:SELECT ID_ITEM From PARTNO_CHKOUT_SPECIAL M Where (Select Count(*)FROM PARTNO_CHKOUT_SPECIAL NWHERE N.ID_ITEM <= M.ID_ITEM) >= 0 AND TYPE_REC=1 ANDFLAG_CHECKED_OUT=0 {maxrows 5}The above would return 101, 104, 105, 110, 111I tried using an (N.ID_ITEM+1)-M.ID_ITEM=0 to try stepping and geterrors, probably incorrect syntax. Can I do this in an SQL statement?

View 6 Replies View Related

T-SQL (SS2K8) :: Select Query With Records And Sequential Numbers

Apr 5, 2014

I have a problem. In my database I have the following numbers available:

101
104
105
110
111
112
113
114

What I need is to get a select query with records and sequentials numbers after it like:

101 0
104 1 (the number 105)
105 0
110 4 (the numbers 111,112,113,114)
111 3 (the numbers 112,113,114)
112 2 (the numbers 113,114)
113 1 (the numbers 114)
114 0

How can I do It?

View 2 Replies View Related

Generate Serial Numbers And Update Column?

Jul 17, 2013

I have two tables. One table has empty column (ID) and I want to generate serial numbers in that column based two tables columns(LoanNum) condition.

Table A

ID LoanNum
Null 1234
Null 2345
Null 3456
Null 4567
Null 5678
Null 6789

Table B

LoanNum
1234
2345
3456
4567
5678
6789
2324
4352
4235

Id is not primary key, but should not duplicates keys, it is just a column want to generate serial number (1,2,3,4...etc) How to generate?

View 5 Replies View Related

SQL 2012 :: Update A Column With A Sequence Of Numbers Starting From 1?

Oct 7, 2015

If Exists ( Select c.name from sys.columns c where object_id = object_id('HH835HP') and C.name = 'ID_1' )
Begin
UPDATE HH835HP
SET ID_1 =
( select ROW_NUMBER() OVER(ORDER BY CHKDTS ASC) AS ID_1 FROM HH835HP ) ;
End;

Obviously... The stuff inside the IF is wrong syntax...I mean

UPDATE HH835HP
SET ID_1 =
( select ROW_NUMBER() OVER(ORDER BY CHKDTS ASC) AS ID_1 FROM HH835HP ) ;

View 4 Replies View Related

Formatting Numbers In A Mixed Column (numbers In Some Cells Strings In Other Cells) In Excel As Numbers

Feb 1, 2007

I have a report with a column which contains either a string such as "N/A" or a number such as 12. A user exports the report to Excel. In Excel the numbers are formatted as text.

I already tried to set the value as CDbl which returns error for the cells containing a string.

The requirement is to export the column to Excel with the numbers formatted as numbers and the strings such as "N/A' in the same column as string.

Any suggestions?



View 1 Replies View Related

Sequential Number In An Update

Oct 27, 2006

this is a slight change to a fequently asked question around here. Ihave a table which contains a "sortorder" column where a user canspecify some arbitrary order for records to be displayed in. Usershave sometimes ordered records the way we used to number lines in aBASIC program (10,20,30, etc.). I'd like to do an update query and fixthis so that every record is in sequential order. I found an examplein this newsgroup of how to do this.However, I have a slight problem! Sometimes, the users duplicated thesortorders. So for example, I might have two records were thesortorder is 20. The query I found in this newsgroup does not work inthat case. Here is some code so that you can see what I mean.create table sorttest (label char(5),sortorder int)goinsert sorttest values ('joe',20)insert sorttest values ('dan',10)insert sorttest values ('jim',44)insert sorttest values ('tom',20)insert sorttest values ('jan',50)-- data dumpselect label, sortorder from sorttest order by sortorder-- I'd like to fix all of the sortorder fields so that they aresequentialupdate sorttestset sortorder = (select count(*)from sorttest subquerywhere sorttest.sortorder <= subquery.sortorder)-- note that tom and joe BOTH HAVE SORTORDER = 4select label, sortorder from sorttest order by sortorderdrop table sorttestThanks in advance for any help.

View 19 Replies View Related

Increasing Column Size

May 12, 2000

Hello,

Does anyone know of a good process to increase a Column size of type char, that already had data in it, without losing the data you already have?

Thanks,

Kevin

View 1 Replies View Related

Update Table With SEQUENTIAL # Based On Criteria

May 9, 2007

***** SQL Server 2005 ********

I have a table that needs to be updated with a sequential number based on criteria.

I am trying to update the SeqID and LinkSeqID with the same sequential number if the ProductID and StoreID are in the same group. For instance the 1st three rows below are in the same group 752534 and 4, therefore the SeqID and LinkSeqID should be 1,2,3 and restart at 1 once the grouping of ProductID and StoreID changes. Please look at the examples below.


SALES Table as IS:
======================================
ProductID StoreID DBRowID SeqID LinkSeqID
======================================
752534 4 1
752534 4 2
752534 4 3
896784 2 4
896784 2 5
896784 4 6
898874 2 7
898968 2 8


This is what the table should look like after the update in complete.

SALES after UPDATE:
======================================
ProductID StoreID DBRowID SeqID LinkSeqID
======================================
752534 4 1 1 1
752534 4 2 2 2
752534 4 3 3 3
896784 2 4 1 1
896784 2 5 2 2
896784 4 6 1 1
898874 2 7 1 1
898968 2 8 1 1



Can anyone HELP me please?

View 4 Replies View Related

T-SQL (SS2K8) :: Create Sequential Aggregate Of A Column Using Sum?

Aug 17, 2015

create a sequential aggregate of a column using sum in tsql.

I want a column that will sum up all hours work by transaction date.

for example

Monday my hours work will be 8 and therefore my total transaction hours will be 8.

Tuesday my hours work will be 8 but I want the total hours of my total transaction hours to 16.

Wed my total hours work will be 5 and I want the total hours of my total transaction hours to 21. etc.

Select myname, weekday, hours worked, Totalhours_ToDate =Sum(hours worked) from table

View 5 Replies View Related

Transact SQL :: Create Sequential Aggregate Of A Column Using Sum?

Aug 17, 2015

I need to create a sequential aggregate of a column using sum in tsql.

I want a column that will sum up all hours work by transaction date.

for example

Monday my hours work will be 8 and therefore my total transaction hours will be 8.

Tuesday my hours work will be 8 but I want the total hours of my total transaction hours to  16.

Wed my total hours work will be 5 and I want the total hours of my total transaction hours to  21. etc.

Select myname, weekday, hours worked, Totalhours_ToDate =Sum(hours worked)from table

View 3 Replies View Related

How To Generate / Populate Already Existing Column With Sequential Data

May 8, 2012

I have a table which is already populated with data (Microsoft SQL 2008). I have now created a new column (int) which i want to populate with sequential numbers so that the new column created will serve let me know how many records exist in the table at a glance.

what SQL statement I need to write that will automatically polulate the newly created column with 1,2,,3,4,5 etc so that I can sort of number the records within the table.

I have 50000 records which I need to number and I really dont want to number the column manually via hand editing.

View 3 Replies View Related

Update With Random Numbers

Jan 2, 2008

I have a table with a field called "host" and I want to replace the value of this column in each row with 'Host' followed by a random number. I have created the below function to do this:
DECLARE @Random varchar;
SELECT @Random = CONVERT(int, (20+1)*RAND())+ 1;
UPDATE AnalogLines Set [Host Name] = 'Host' + @Random
 
This sorta works... the problem is, the random number is determine and then the SAME random  number is applied to each row. I need a different random number for every row. Any ideas?

View 3 Replies View Related

RE:PHONE NUMBERS UPDATE

Aug 14, 2001

I am trying to update a bunch of phone numbers in a sql 6.5 db.
The phone numbers are in the following formate.
(aaa)-xxx-cccc
I need to update xxx to yyy. Has anyone done this before.
Please help.


Thanks in advance

Ken

View 3 Replies View Related

T-SQL (SS2K8) :: Update Field Value For Numbers Only

May 13, 2014

Large design flaw, I know, but we have a table with a varchar field which contains alpha - numeric values. I need to change just the numerics, which can be in an position on the field:

Sample data of the field:
Rec1: Sally Morgan 201-555-1212
Rec2: 555-4040 John Smith
Rec3: Jane Houstin 201-555-6452 ext1223

Desired result:
Rec1: Sally Morgan 999-999-9999
Rec2: 999-9999 John Smith
Rec3: Jane Houstin 999-999-9999 ext9999

There's a bunch of UDFs out there for selecting just the numerics, but I'm having trouble throwing it into a viable script for repeatable execution.

View 8 Replies View Related

Multiply Numbers In A Column

Mar 21, 2002

Hi

I'm trying to find a decent way of multiplying a set of numbers in a column without using a cursor in T-SQL.

There is no 'Product' aggregate function that I'm aware of in SQL 7 or 2000. The workaround I'm currently using is this :

SELECT EXP(SUM(LOG(ColumnName))) FROM tblName

This works fine, except when negative numbers are introduced. The LOG function does not allow negative numbers and therefore returns a domain error and the negative number is eliminated from the aggregate.

I could use a cursor to do the multiplication, however, this is proving too slow for the bulk calculations involved.

If anyone has any ideas or suggestions, then that would be much appreciated.

thanks....Tom

View 1 Replies View Related

Add New Table Column With Numbers

Jul 19, 2007

Hello.

Whats the easiest way to add a column with a numeration to my table?

I want the users to have an easier life finding on which row they are
talking.

I preffer of course doing it in reporting service and not adding a
column in my dataset.

Thanks.

View 1 Replies View Related

STUCH WITH SSN NUMBERS COLUMN....HW TO DO

Apr 23, 2008



OK I HAVE AN INTERESTING SITUATION HERE.

I HAVE AN SSN COLUMN.

SSN NUMBER HAS 9 NUMERIC DIGITS.

NOW IN THE SSN COLUMN I HAVE A LOT OF BAD SSN WHICH CONTAIN ONLY 3 OR ONLY 4 OR ONLY 5 AND SO ON DIGITS.

HOW CAN I FILTER THESE ONES OUT SO THAT I CAN MAKE AN EXCELL REPORT OF THIS DATA.

I AM THINKGING OF USING CONDITIONAL SPLIT.

BUT HOW SHOULD I GO ABOUT IT.

PLEASE LET ME KNOW THE COMMAND

View 1 Replies View Related

Removing Numbers From A Column

Oct 11, 2007



Hi,

I have the following tables :




Code Block
Create table #EmployeeList(empname nvarchar(20), emptype char(5))

Insert INTO #EmployeeList('Cary zzz',null);
Insert INTO #EmployeeList('01 Jack',null);
Insert INTO #EmployeeList('02 Tommy',null);
Insert INTO #EmployeeList('03 Ricardo',null);
Insert INTO #EmployeeList('04 Jack',null);
Insert INTO #EmployeeList('Les zzz',null);
Insert INTO #EmployeeList('05 Tim',null);

The final data looks like this :

Cary zzz NULL
01 Jack NULL
02 Tommy NULL
03 Ricardo NULL
04 Jack NULL
Les zzz NULL
05 Tim NULL






1. I want to delete all rows which have 'zzz' in it.
2. I want to remove the numbers from the empname column




Code Block
Expected Output :

Jack NULL
Tommy NULL
Ricardo NULL
Jack NULL
Tim NULL






Can anyone help me please with the query?

thanks.

View 4 Replies View Related

Convert Sql Smalldatetime Column Into Numbers

Aug 27, 2004

HI all;

I have a simple question to ask; I need to create a column with the data from my DOB column (which has the smalldatetime type attached to it). I know how to do that but I am not too sure how to convert the data from that column int normal character for example when I copy it into my newly created column and change the type to varchar I get this jan 16 1979 from this date 1979/01/16. But I actually want the data to look like this 19790116, so in effect I just want to take out the slashes.

Any help would be highly appreciated, thanks all.

View 1 Replies View Related

Ordering A Column In Descending With Numbers First

Oct 8, 2013

I have a Column which has both numeric values and Alphabets in them.I want to sort them in descending with numbers first and then Alphabets later.

Example:

Source column:
2008
2005
2010
2013
All-Year
Month-year

Required Output:

Source Column:
2013
2010
2008
2005
Month-Year
All-year

View 4 Replies View Related

Reuse Numbers In Identity Column

Mar 4, 2008

Hello,

I have an ID column which is an Identity column, and it counts from 1 upwards.

If I have 10 records, I have ID's number 1 to 10.
If I then add another record, it will give the ID number 11.

Imagine I then delete ID number 9
Is it possible to get the next record I create to take number 9 instead of 12 ?

View 5 Replies View Related

Gradually Add O Substract Numbers In A Column

Nov 22, 2007

how do I gradually add o substract numbers in a column for example if I have



total
deposito
test

120

120


80
40

77

117

7

124


4
120


i need in the test column:
if the number is in the total column the number in test is added
if the number is in the deposito column the number in test is substracted

i have this query:


SELECT gir_cantidad as total,null as deposito,'operation' as test

FROM giros inner join corresponsales on cor_corresponsal_id = gir_corresponsal_id where gir_fecha >= '11/21/2007' and gir_fecha <= '11/22/2007 23:59:59' and gir_fecha_anul is null and gir_agencia_id = 1

UNION

select null as total,paa_valor as deposito,'operation' as test from pagosagencia where paa_fecha >= '11/21/2007' and paa_fecha <= '11/22/2007 23:59:59' and paa_agencia_id= 1 order by gir_fecha

In column test i need the functionality to add and subtract the columns total and deposito

Please help

View 4 Replies View Related

Transact SQL :: How To Update ItemOrder With Ascending Numbers Starts With 1 For Child Items

Jul 23, 2015

I have a below table,

DECLARE @TBL TABLE (ItemId INT IDENTITY(1,1), ItemName NVARCHAR(20), ParentItemName NVARCHAR(20), ItemOrder INT, ReportId INT)
INSERT INTO @TBL (ItemName, ParentItemName, ItemOrder, ReportId)
VALUES('Item1', NULL, 1, 5),('Item1-Child1', 'Item1', 0, 5),('Item1-Child2', 'Item1', 0, 5),('Item2', NULL, 2, 5),
('Item11', NULL, 1, 6),('Item12', NULL, 2, 6),('Item12-Child1', 'Item12', 0, 6),('Item13', NULL, 3, 6)
SELECT * FROM @TBL

Here,
1. for all ReportId, child items's ItemOrder  = 0
2. example, for ReportId = 5, both child items ("Item1-Child1" & "Item1-Child1") of parent "Item1" has ItemOrder = 0

I need to,
1. update all child items with ascending numbers starts with 1 against each parent and each report.
2. for each different parent or different report, order by should starts with 1 again.

View 2 Replies View Related

Identity Column Jumped 1.8 Billion Numbers

Aug 19, 1999

After moving our database between servers, one table had a hiccup in it's
identity column. The number jumped from 761 to 1886863475 on the next
insert. This is a production server and I didn't catch it until yesterday.
So I have several days worth of numbers in a central table. I can't clean
them out, but I wondered if I could do the following:

DBCC CHECKIDENT ('table_name', RESEED, 800)

I tested it on our development server and it doesn't seem to cause any
problems. I know that when we get to 1.8 billion on the identity column
again we'll get an error, but I'm willing to risk it.

A few questions. 1) Am I insane for trying this? 2) Has anyone else ran into
a similar problem and what did you do to fix it? 3) If I do this, is there
anything in particular to watch out for? 4) What caused the jump in the
first place?

My other option is to change the datatype from int to decimal(19) or
something along those lines. This will upset our programmers and I'll have
to change all my foreign keys (not a big deal, just a pain).

Any input at all here would be appreciated.

Thanks,

Grant

View 1 Replies View Related







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