How Can I Create A Sequence ?
Jul 16, 2001
Hi,
I would like to know how it is possible to create a sequence with sql server 2000
With Postgres SQL i create the sequence essai : create sequence essai START 1;
but i don't know what is the sql command.
Thanks in advance.
Marie
View 1 Replies
ADVERTISEMENT
Jun 2, 2008
In oracle, I can setup a sequence generating unique ids and query the next value (which is used as a unique identifer). I know sql server has the identity field but I need to query the next val so I can insert rows into multiple tables.
When a user submits a form, I want to take the dept info from the form (in c# asp.net 2.0) and grab the first two characters. Then query the next val from a table that holds an int.. During insert into two tables it would be something like "IT100" or "SL101". But it needs to be unique.
Is there a way to setup a table in sql server similar to a sequence where I can just query the next val (or some other way?). Remember, I cant do this as identity because I need the key being inserted in other tables during form submit.
It seems very simple but I can't seem to find an answer online that allows me to query the next val in my code then perform the multiple inserts.
Thanks in advance for any assistance you can lend on this,
dev1aspnet
View 2 Replies
View Related
Jun 5, 2012
I have created a view based on joining 3 tables, however, it is not possible to have a unique field in the view which I must need it and I must create index on some other fields. Is there any way to create sequence number or uniqie field in mssql view.
View 13 Replies
View Related
Jul 29, 2015
I'm looking to see if there is a way to populate starting number for the sequence from a max value of a table.
CREATE SEQUENCE test_seq
AS [int]
START WITH (select max(col1)+1000 from table1)
INCREMENT BY 1
MINVALUE 1
MAXVALUE 2147483647
CACHE
GO
View 3 Replies
View Related
Apr 17, 2008
Greetings
I was directed to post this here. I am thinking of creating a script that generates another script for creating/dropping tables, indeces, FK, views, stored procedures..etc in the correct sequence in a specific database. I accept the fact this script is dangerous (like if I ran it on production server). But it sure will be very helpful when moving our SQL objects from development to qa and then to production. Is this worth it? Have you see anything that generates such a thing using sys.objects,sys.indexes,sys.foreign_keys etc?
Thanks
View 1 Replies
View Related
Mar 28, 2006
Hi,
I got 5000 rows in source and when i am sending the data to destination it has to create a sequence generator number for each row.
Can any one help me which transformation do i need to take for doing this in SSIS.
View 10 Replies
View Related
Feb 22, 2005
Hi, can anyone teach me how to automatic create a invoice number and insert or update it to a column?
View 2 Replies
View Related
Feb 6, 2004
Hi,
How can I generate a sequence No. using a simple SELECT statement.
like
declare @key
set @key = 1
SELECT @key, e.name from Employee
Now I want to display name of the employee and Key value which should get incremented automatically for each employee..
Is there any way?
Please help me..
View 1 Replies
View Related
Dec 18, 2007
hi
i've been asked to write a sql sequence for a database i'm building but i haven't been using SQL very long and i have no idea how to write a sequence. Does anyone know anything about sql sequences?
thanks
jessica
View 14 Replies
View Related
Jul 20, 2005
Hi,I need little help with Ms SQL Server 2000. I would like to know how tocreate sequence or something like that. I want to have an automatic counterfor each row in one entity, so then I can do something like this:INSERT INTO table VALUES (use sequence(something), value, value, .... )Can you please help me?thxTomas
View 1 Replies
View Related
Apr 9, 2007
I have a SQL 2005 stored procedure to generate an email when passed parameters such as receipient, subject etc
One of the paramteres passed to it is @body which is the body text of the message. I want to be able to add a couple of blank lines and then some footer information. This is working right now except I can't find the right way to add newlines into the string within the store procedure, so my footer information just tags right on after the bodytext.
I have tried but that literally adds the two characters and n
Can anyone advise how to generate newlien sequences in T-SQL.
Regards
Clive
View 1 Replies
View Related
Apr 27, 2008
Hi all.
In one table fields vales are 9, 5, 7, 2, 5, 6, 44, 67, 789.
I want to get 5 high values so please can you write sql query for this question.
Thanks.
Zahyea.
View 1 Replies
View Related
Apr 16, 2002
Hi, I've a question, if I've the LSN (Log Sequence Number) of a transaction, keep with the program "Log Explorer", can I know which is the IP of the user that have do the transaction (perhaps serching in a log file of the Win 2000 Server) ?
10x,
Clara
View 1 Replies
View Related
Dec 29, 1998
In SQL 6.5 object dependencies window, what does the sequence number means?
Thanks,
Sam
View 1 Replies
View Related
Sep 1, 2004
Hi,
I have a question with this query -
SELECT * FROM table1 WHERE column1 = 'T_C_%';
This query returns rows where column1 = "T_Care", "T_CRP" etc etc, whereas I was expecting only rows where column1 = "T_C_Tail", "T_C_Head"
However, when I use an escape character(/), the results are more in the lines of the expected results.
Can somebody explain this?
cheers/- Pradeep
View 2 Replies
View Related
Nov 17, 2005
I have the following stored procedure:
CREATE PROCEDURE dbo.ABR_HDR_INSERT
@id int output,
@status int,
@mode int,
@sessid varchar(100)
AS
declare @ay char(4)
declare @ddo char(4)
declare @abrid varchar(50)
declare @seq_no int
SELECT @ddo = a.DDO_DSCR_SHORT
FROM dbo.DIM_DDO a
JOIN dbo.Temp_ABR_HDR b
ON a.DDO_ID = b.DDO
WHERE b.SESSIONID = @sessid
SELECT @ay = AY
FROM dbo.Temp_ABR_HDR
WHERE SESSIONID = @sessid
-- set the default seq_no
SELECT @seq_no = 1
-- get the max abrid. if no record return the seq_no will be 1
SELECT @seq_no = convert(integer, max(right(abrid, 4)))
FROM dbo.ABR_HDR
WHERE left(abrid, 7) = @ay + @ddo
-- convert @seq_no to string prefix by 0
SELECT @abrid = @ay + @ddo + right('0000' + rtrim(convert(char(4), @seq_no)), 4)
Insert into dbo.ABR_HDR (ABRID, HDR_MODE, HDR_DDO, HDR_AY, HDR_REQUESTOR, HDR_DT, HDR_SUBJECT, HDR_DESCRIPTION, HDR_STATUS)
SELECT
@abrid,
@mode,
DDO,
AY,
REQUESTOR,
DT,
SUBJECT,
DESCRIPTION,
@status
FROM dbo.Temp_ABR_HDR
SELECT @id = @@identity
return @id
GO
ABRID gets inserted as a <NULL> value. I can't figure out why? If I comment out the following then ABRID will insert without the sequence number:
CREATE PROCEDURE dbo.ABR_HDR_INSERT
@id int output,
@status int,
@mode int,
@sessid varchar(100)
AS
declare @ay char(4)
declare @ddo char(4)
declare @abrid varchar(50)
declare @seq_no int
SELECT @ddo = a.DDO_DSCR_SHORT
FROM dbo.DIM_DDO a
JOIN dbo.Temp_ABR_HDR b
ON a.DDO_ID = b.DDO
WHERE b.SESSIONID = @sessid
SELECT @ay = AY
FROM dbo.Temp_ABR_HDR
WHERE SESSIONID = @sessid
-- set the default seq_no
--SELECT @seq_no = 1
-- get the max abrid. if no record return the seq_no will be 1
--SELECT @seq_no = convert(integer, max(right(abrid, 4)))
--FROM dbo.ABR_HDR
--WHERE left(abrid, 7) = @ay + @ddo
-- convert @seq_no to string prefix by 0
--SELECT @abrid = @ay + @ddo + right('0000' + rtrim(convert(char(4),@seq_no)), 4)
SELECT @abrid = @ay + UPPER(@ddo)
Insert into dbo.ABR_HDR (ABRID, HDR_MODE, HDR_DDO, HDR_AY, HDR_REQUESTOR, HDR_DT, HDR_SUBJECT, HDR_DESCRIPTION, HDR_STATUS)
SELECT
@abrid,
@mode,
DDO,
AY,
REQUESTOR,
DT,
SUBJECT,
DESCRIPTION,
@status
FROM dbo.Temp_ABR_HDR
SELECT @id = @@identity
return @id
GO
So, the code that sets the sequence number is what is causing the <NULL> value.
Any help is appreciated.
Thanks,
-D-
View 4 Replies
View Related
Feb 1, 2007
Hi,
I am migrating a project from Oracle to SQLServer and must use the same DDL.
The entities have compound primary keys. In Oracle I ensure the compound key is unique by using a sequence table to generate one of the values for the compound key.
Does SQL Server have sequence tabels or does anybody know a way to get it do something similar?
Thanks
View 1 Replies
View Related
Apr 27, 2007
Hi,
How do I determine the max value for Sequence table in SQL Server?
Regards
View 7 Replies
View Related
Oct 3, 2007
suppose I have the following table grouped by memid
memiddx
3455
3322
3232
433
43434
I want to attach sequence number for each unique value of dx per memid as
below
memiddxSEQ
34551
33222
32323
4331
434342
I am using a cursor right now and it takes a lot of time if my table is large.
Is there a more efficient way of doing this.
Thanks much.
View 3 Replies
View Related
Jan 11, 2008
is it possible to generate a number sequence in a query (without using loop). I want the output to look as
-------
ID
-------
1
2
3
4
5
6
7
8
9
....
upto the last number I give in the query
View 13 Replies
View Related
Oct 16, 2014
I am not sure about the ANSI/ISO rules on this? We have a SEQUENCE and insert it into a table.
CREATE SEQUENCE Cheque_Seq
AS INTEGER
START WITH 1
INCREMENT BY 1;
CREATE TABLE Cheque_Book
(cheque_seq INTEGER*NOT NULL PRIMARY KEY,
cheque_amt DECIMAL (15,2) DEFAULT 0.00 NOT NULL);
If I do an insertion with the SEQUENCE in a transaction and then ROLLBACK the transaction, what happens to the sequence value? My thought is that the value should reset to the state it was in before the transaction (basic definition of a ROLLBACK). But it does not in the products I have looked at.
View 1 Replies
View Related
Apr 4, 2008
Hi SqlGurus,
I have created table T1 as
created table t1 (no int not null primary key,name varchar(30))
i have created a sequence for this table
when i give the following insert statement
insert into t1 (name) values ('xyz')
the next sequence val should be inserted in column no
this is done generally in oracle with before trigger
how about here .Can we do this ?
View 7 Replies
View Related
Mar 10, 2006
Hi
I need to create a function that will return a sequence number. The reason I need this to be a function is that I will use the function to create a view. In Oracle I would do something like this:
create sequence seq;
create or replace function f return number
as
l_seq number;
begin
select seq.nextval into l_seq from dual;
return l_seq;
end; /
create or replace view v as select f from dual;
Since Sql Server does not have a sequence object I have created a sequence table with a identity column and a procedure that inserts a dummy variable and returns the identity id. This works ok but to get my sequence number I must declare a variable, execute the procedure and select the return value.
I need the procedure to be a function so that I can use it to create my view. Since I cannot use DML in a function and I cannot call a procedure from a function I am stuck. Do I have to create an extended procedure ? Any help is appreciated
View 8 Replies
View Related
Mar 28, 2007
hey all,
im having some problem to do this. i have this one table, that has sequence for other table.
table : tblpicksequence (this sequence is dynamic eg : Non=1, cons=2, RET=3)
picktypepicksequenceitemref
RET1x1
Non2x1
Cons3x1
i need to select record from other table depend on tblpicksequence sequence
table : tbldetail
idRETNonCons
1001
2110
3100
4 001
so base on tblpicksequence, RET=1, NOn=2, Cons=3, i need to list the record from tbldetail :-
i.list all RET=1
ii.if (i) not exists list all Non=1
iii.if (ii) not exists list all Cons=3
i expect :-
idRETNonConspicksequencepicktype
21101RET
31001RET
~~~Focus on problem, not solution~~~
View 8 Replies
View Related
Nov 5, 2007
I'm looking for a query that will look at an Id field and if it occurs more than once then returns the count of the times it occurs. For Example,
ID Code GetSequence
4 239 1
4 241 2
4 3243 3
View 5 Replies
View Related
Dec 26, 2007
Hello to every body
I need to know about sequence of execution in a select command.
I have a sql command that use a function.some thing like:
select id, function(item)
from tbl
where conditions...
I want to know that if my function on item execute before where section or vise versa.
I try to explain it more. I want to know that sql engine fetch rows accordin to where clause and then execute my function or execute my funtion and then fetch the rows according to where clause.
If you have a document or some thing that explain about sql engine and sequence of execution please let me know.
Your help is really appriciated.
View 4 Replies
View Related
Jan 23, 2008
Hi,
I have a table in which there is 5 column ...one with numbers like...1,2,3,4,..20...and one column is with description....and other column with other details...
Now I want to disply my results in sequence followed by 1,2,3,4,5,17,18,15,16,10,11,20 with all other columns...so can anybody suggest me what to do..?
View 3 Replies
View Related
Feb 5, 2008
hi all,
how to restore Transactional log files in Sequence,
Restore log Db_name
from disk='d:ackup_name.trn'
...
pls required syntax for it
thanx for any help
View 6 Replies
View Related
Mar 15, 2008
Guys,
I have to generate sequence for distinct group of values for example
intially seq is set to 1 through out the table
categorydescidseq
__________________________________
AccountingAccounting61
AccountingAccounting72
AccountingFinal81
AccountingFinal92
AddendumAddendum 101
Is there any way to accomplish this?
Any suggestions and inputs would help
Thanks
View 4 Replies
View Related
Apr 4, 2006
Hello all,Iīm currently using a SQL Serve 2K. Would like to do a selectwhich returns the row number - this should not be physically stored inthe database. So for example, I would like to do a query against theCUSTOMER table and receive:* rowID || name1 Evander2 Ron3 Scoth4 JaneI donīt want to store the ID, because if I change the order byclause, the sequence may modifiy, and, for another example, having thesame set of data, I would receive:* rowID || name1 Scoth2 Ron3 Jane4 Evander could someone help me ?best regards,Evandro
View 3 Replies
View Related
Jun 19, 2006
Hello,Since SQL Server has no sequence generator, I wrote my own. (I claimno ownership of it as it is closely modeled after earlier discussionson this topic.) I have included the sql statements below.While it works independently on its own, It seems to lock in multi-userenvironments or in nested-transactions. It s funny really: I have mymain transaction, but the sequence generator below forces anothertransaction, which I do not really care for. I cannot remove the extratransaction from the sequence generator because I would like to discardany values it retrieved, regardless of whether the main transactionsucceeded or failed.Any suggestions?--------------------------------------------------------------------------------create table my_sequence (name varchar(10), seq int identity (1, 1))godeclare @next intbegin transactionupdate my_sequence set seq = seq + 1 where name = 'abc';select @next = seq from my_sequence where name = 'abc';commit transaction---------------------------------------------------------
View 6 Replies
View Related
Apr 29, 2006
I have 2 tables which tab B depends on the record on tab A. In publisher, records are generated to tabA before some audit information record to tabB. In subscriber, there is replication error that the trigger in tab B couldn't find the corresponding record in tab A and cause the transactional replication error. And I found the comand_id within the same xact_segno of record in tab B is smaller than that of record in tab A. Does it mean the data in tab B replicate before tab A?
Also, how to know the replication sequence to the subscriber?
Thanks in advance!
View 1 Replies
View Related
Oct 19, 2007
Hi fellows
I have these values with a PK and length.
PK length
dd1 2
dd1 4
dd1 6
dd1 8
dd1 9
dd2 1
dd2 3
dd2 6
dd2 9
dd3 3
dd3 4
dd3 9
dd3 15
dd3 25
I want to create another column showing a sequency like this THIS MEANS THAT WHEN I CHANGE THE PK I HAVE TO START WITH CERO.
PK FROM TO
dd1 0 2
dd1 2 4
dd1 4 6
dd1 6 8
dd1 8 9
dd2 0 1
dd2 1 3
dd2 3 6
dd2 6 9
dd3 0 3
dd3 3 4
dd3 4 9
dd3 9 15
dd3 15 25
CHEERS
View 4 Replies
View Related