Click here to Skip to main content
15,902,445 members
Home / Discussions / Database
   

Database

 
GeneralRe: Lookups Pin
Luc Pattyn28-Jan-09 5:06
sitebuilderLuc Pattyn28-Jan-09 5:06 
GeneralRe: Lookups Pin
Wendelius28-Jan-09 5:35
mentorWendelius28-Jan-09 5:35 
QuestionTo get the current value for SORT_IN_TEMPDB Pin
Arun Abraham Jose27-Jan-09 18:59
Arun Abraham Jose27-Jan-09 18:59 
AnswerRe: To get the current value for SORT_IN_TEMPDB Pin
Wendelius27-Jan-09 19:42
mentorWendelius27-Jan-09 19:42 
GeneralRe: To get the current value for SORT_IN_TEMPDB Pin
Arun Abraham Jose30-Jan-09 0:33
Arun Abraham Jose30-Jan-09 0:33 
GeneralRe: To get the current value for SORT_IN_TEMPDB Pin
Wendelius30-Jan-09 7:27
mentorWendelius30-Jan-09 7:27 
GeneralAutoincrement per field Pin
Mustafa Ismail Mustafa27-Jan-09 18:56
Mustafa Ismail Mustafa27-Jan-09 18:56 
GeneralRe: Autoincrement per field Pin
Wendelius27-Jan-09 19:35
mentorWendelius27-Jan-09 19:35 
You could do this with triggers. Depending on the business rules you would have a bit different implementations. For example if new record gets the maximum value for patient + 1, you would have something like:
CREATE TRIGGER SomeTriggerName
ON YourTableName
AFTER INSERT
BEGIN
   DECLARE @keyValue int;
   DECLARE @patientID int;
   DECLARE newRows CURSOR
   FOR SELECT PrimaryKeyColumnName, PatientId
   FROM inserted;
   --
   OPEN newRows;
   FETCH NEXT FROM newRows INTO @keyValue, @patientId;
   WHILE @@FETCH_STATUS = 0
   BEGIN
      UPDATE YourTableName
      SET    AdmittanceID = (SELECT MAX(AdmittanceID)
                             FROM   YourTableName
                             WHERE  PatientID = @patientId)
      WHERE  YourTableName.PrimaryKeyColumn = @keyValue;
      --
      FETCH NEXT FROM newRows INTO @keyValue, @patientId;
   END
   CLOSE newRows;
   DEALLOCATE newRows;
END

And if you need that the patientid does not have gaps, you would create a delete trigger where you reorder numbering for records having the same patientid as deleted row(s).

The need to optimize rises from a bad design.My articles[^]

GeneralRe: Autoincrement per field Pin
Mustafa Ismail Mustafa27-Jan-09 20:51
Mustafa Ismail Mustafa27-Jan-09 20:51 
GeneralRe: Autoincrement per field Pin
Wendelius27-Jan-09 20:53
mentorWendelius27-Jan-09 20:53 
GeneralRe: Autoincrement per field [edit] [modified] Pin
Mustafa Ismail Mustafa27-Jan-09 21:15
Mustafa Ismail Mustafa27-Jan-09 21:15 
GeneralRe: Autoincrement per field Pin
Wendelius27-Jan-09 21:49
mentorWendelius27-Jan-09 21:49 
GeneralRe: Autoincrement per field Pin
Mustafa Ismail Mustafa28-Jan-09 1:16
Mustafa Ismail Mustafa28-Jan-09 1:16 
GeneralRe: Autoincrement per field Pin
Wendelius28-Jan-09 1:24
mentorWendelius28-Jan-09 1:24 
GeneralRe: Autoincrement per field Pin
Mustafa Ismail Mustafa28-Jan-09 1:28
Mustafa Ismail Mustafa28-Jan-09 1:28 
GeneralRe: Autoincrement per field Pin
Wendelius28-Jan-09 1:43
mentorWendelius28-Jan-09 1:43 
Questionhow the oracle packages are implemeted in the sql server Pin
lakshmichawala27-Jan-09 17:33
lakshmichawala27-Jan-09 17:33 
AnswerRe: how the oracle packages are implemeted in the sql server Pin
Wendelius27-Jan-09 19:44
mentorWendelius27-Jan-09 19:44 
GeneralRe: how the oracle packages are implemeted in the sql server Pin
lakshmichawala27-Jan-09 20:21
lakshmichawala27-Jan-09 20:21 
GeneralRe: how the oracle packages are implemeted in the sql server Pin
Wendelius27-Jan-09 20:33
mentorWendelius27-Jan-09 20:33 
QuestionSimultaneous access to MS Access Pin
Member 382292227-Jan-09 12:20
Member 382292227-Jan-09 12:20 
AnswerRe: Simultaneous access to MS Access Pin
Wendelius27-Jan-09 12:46
mentorWendelius27-Jan-09 12:46 
GeneralRe: Simultaneous access to MS Access Pin
Member 38229225-Feb-09 13:48
Member 38229225-Feb-09 13:48 
AnswerRe: Simultaneous access to MS Access Pin
PIEBALDconsult27-Jan-09 15:13
mvePIEBALDconsult27-Jan-09 15:13 
GeneralRe: Simultaneous access to MS Access Pin
Member 38229225-Feb-09 13:50
Member 38229225-Feb-09 13:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.