473,385 Members | 1,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Sequence Query in Access

Hi...I had a question regarding sequence utilization in query. I have an access database where i add a new field which is AltId where i want the field to filled with numeric values that start from 1. Its some sort like auto increment but i wan it run by query.how can i do so?
I plan do do with sequence syntax...but i dont know how to use it efficiently
i do like below.

Create SEQUENCE sequencename1 START WITH 1 INCREMENT BY 1 then
ALTER TABLE Alternator ALTER AltID RESTART WITH 1

but i got error....How plsssssssssss help me......Urgent...Thanks in advance
Apr 28 '08 #1
5 5959
FishVal
2,653 Expert 2GB
I plan do do with sequence syntax...but i dont know how to use it efficiently
i do like below.

Create SEQUENCE sequencename1 START WITH 1 INCREMENT BY 1 then
ALTER TABLE Alternator ALTER AltID RESTART WITH 1
Hi, there.

JetSQL unlike PLSQL has no SEQUENCE facility. It uses Autonumber type field instead

I have an access database where i add a new field which is AltId where i want the field to filled with numeric values that start from 1. Its some sort like auto increment but i wan it run by query.how can i do so?
What do you mean? Do you mean to store the numbers in table? Do you mean query returning enumerated records?

Kind regards,
Fish
May 1 '08 #2
i want to insert values into not an auto increment fields . I want the field fill the values start from 1 till the n last record. i wan to run a query to do so. plzzz help me by query.
May 2 '08 #3
FishVal
2,653 Expert 2GB
i want to insert values into not an auto increment fields . I want the field fill the values start from 1 till the n last record. i wan to run a query to do so. plzzz help me by query.
I would recommend you to write a very simple VBA function with a static variable incrementing the variable value each time the function is called, then use it in update query to generate number sequence.

Expand|Select|Wrap|Line Numbers
  1. 'varDummy is used to enforce Access to run it for each record in query
  2. 'if varDummy is missed then enumerator reset
  3. Public Function NumSeq(Optional varDummy As Variant) As Long
  4.  
  5.     Static lngNum As Long ' static var preservs value between calls
  6.  
  7.  
  8.     If IsMissing(varDummy) Then
  9.         lngNum = 0
  10.     Else
  11.         lngNum = lngNum + 1
  12.     End If
  13.     NumSeq = lngNum
  14.  
  15. End Function
  16.  
  17. Public Sub ApplySeqToTable()
  18.  
  19.     'reset enumerator
  20.     NumSeq
  21.     'run update query
  22.     DoCmd.RunSQL "UPDATE t1 SET t1.lng = NumSeq(t1.txt);"
  23.  
  24. End Sub
  25.  
Regards,
Fish
May 2 '08 #4
"This operation requires an open database " error appear
May 3 '08 #5
FishVal
2,653 Expert 2GB
"This operation requires an open database " error appear
Ok.
SQL statement
Expand|Select|Wrap|Line Numbers
  1. UPDATE t1 SET t1.lng = NumSeq(t1.txt);
  2.  
I've posted above has the following definitions
  • t1 - name of the table
  • lng - name of the field number sequence is stored to
  • txt - name of any (no matter which) field in the table
You need to replace it with that relevant in your database.

Regards,
Fish

BTW, if you add Autonumber field it will be filled with number sequence automatically.
May 3 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Hemant Shah | last post by:
Folks, I am having problem running select query from a sequence. I get SQL0204N error. I am running UDB 8.2 on AIX 5.2. # oslevel 5.2.0.0 # db2level DB21085I Instance "dba2test" uses...
6
by: GSpiggle | last post by:
I have a database with records that should have a consecutive number ID (Check Register). Also has other records (deposits and adjusting entries) that don't fit in the number range so...
3
by: DFS | last post by:
FYI, Using DLookup("ResultsField","Pass-thru query") consumes 2 SEQUENCE numbers each time it's called. Anyone know why?
3
by: Robert McGregor | last post by:
Hi there, I was wondering if anyone could help with this problem. I have a table with about 250,000 rows that relate to files that have been processed elsewhere in our business. Each file has...
4
by: Sim Zacks | last post by:
I am in the process of converting an existing database to PostGreSQL and wrote a generic script to update all of the sequences as they default at 1. I thought it would be useful to other people who...
5
by: Eric E | last post by:
Hi, I have a question about sequences. I need a field to have values with no holes in the sequence. However, the values do not need to be in order. My users will draw a number or numbers from...
14
by: Maxximvs | last post by:
G'day Having a day where the brain noodle will not comprehend so I though I'd post the question. I have a table (called Vendors) which has two fields (Sequence, a unique number but not marked...
7
by: MayoM | last post by:
Access 2003 has suddenly reordered the sequence of columns in a datasheet subform. Specifically the last column has stayed in place but the others are back to front. There are about 50 columns in...
2
by: peter stickney | last post by:
I am running CentOS 5.2, with all current updates PHP 5.1.6 - PHP 5.1.6 (cli) (built: Jul 16 2008 19:53:00) Copyright (c) 1997-2006 The PHP Group Zend Engine v2.1.0, Copyright (c) 1998-2006...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.