sql server - sql composite key with identity -


Is it possible to make a composite key in SQL 2000 as such:

event_id id2
ADF & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; 1
ADF & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; 2
ADF & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; 3
Cfg & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; 1
Cfg & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; 2 & nbsp; Edf & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; 1 /

where id2 restarts count on every change of event_id I need the numbers to be properly used either by using a table or other SELECT statement.

EDIT: I can not be clear that I only want to temporarily join this table.

This is an answer I gave to another poster, but it shows what you are asking :

  select seqid = identity (integer, 1, 1), event_id, celcat200809.dbo.CT_EVENT_STAFF ES join S.name probe #EventNames event_id from left celcat200809.dbo.CT_STAFF ES.staff_id = S.staff_id command on S., select S.name EN.event_id, Max (case seqid - minseqid when 0 then end all other 'EN.name')) + Max (be organized ('+' + matter seqid - minseqid when 1 then EN.name or zero end, '')) + Max (to be organized ('+' + Mam When seqid - minseqid 2 then EN.name or zero end, '')) + Max (to be organized ('+' + case seqid - minseqid 3 then EN.name either tap end, '')) + max ( Callas ('+' + case seqid - minseqid 4 then EN.name or zero end, '')) + Max (to be organized ('+' + case seqid - minseqid 5 then EN.name or zero end, '') ) + Max (to be organized ('+' + case seqid - minseqid when 6 then EN.name or zero end, '')) + Max (to be organized ('+' + case seqid - minseqid 7 then EN.name Zero end, '')) + Max (to be organized ('+' + case seqid - minseqid when 8 then show EN.name New end, '')) + Max (to be organized ('+' + case seqid - minseqid when 9 then EN.name or zero end, '')) + Max (collage ('+' + CECID - Minneid when EventName by #EventNames Group from #Eventname N Inner Join (SELECT event_id, minseqid = min (seqid)) on x on.nvent_id = X.event_id GROUP BY EN.event_id <10 an nnan else nul & > 

You can ignore 10 maximum () expressions. The main parts are: - Paste prices into a template table with an identity column, sorted by group. - Get a minimum value per group with a group query (table X derived above) - Reduce the minimum value from the identity value (and 1 if you want to start numbering at 1) and the voice you have numbers that are 1 for each Restart Group on!

If you are going to use the results of selecting more than two times, then by adding another int column to the temporary table at the time of construction, instead of computing each number, it will be replaced with a new number Update Pahr I guess that when it is better to update ... the test is in order.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -