Board index » delphi » MS SQL 6.5 Stored procedure

MS SQL 6.5 Stored procedure

I am a new with MS SQL and reading documentation I didn't found way how to
implement stored procedure which will set present date-time (GetDate()) in
some record datetime field on insert event (primary key is not autoinc - I
solve probem with autoinc). Something like this Interbase trigger:

Triggers on Table SOMETABLE:
TRIGGERNAME, Sequence: 0, Type: BEFORE INSERT, Active
as begin  new.SOMEDATE = "now"; end

Help, please !

Sinisa

 

Re:MS SQL 6.5 Stored procedure


Quote
"Sini1a Vuleta" wrote:

> I am a new with MS SQL and reading documentation I didn't found way how to
> implement stored procedure which will set present date-time (GetDate()) in
> some record datetime field on insert event (primary key is not autoinc - I
> solve probem with autoinc). Something like this Interbase trigger:

> Triggers on Table SOMETABLE:
> TRIGGERNAME, Sequence: 0, Type: BEFORE INSERT, Active
> as begin  new.SOMEDATE = "now"; end

> Help, please !

> Sinisa

If this were not a TRIGGER and done as a normal Stored procedure using
MS SQL
it would be something like this:

PROCEDURE Add_Customer
          @Customer_ID_int INT,
          @Customer_First_Name_vch VARCHAR(50),
          @Customer_Last_Name_vch VARCHAR(50),
          @Customer_Email_Address_vch VARCHAR(50

AS

INSERT INTO Customer
     VALUES (
             @Customer_ID_int,
             @Customer_First_Name_vch,
             @Customer_Last_Name_vch,
             @Customer_Email_Address_vch,
             GetDate()
            )

GO

The GetDate() call is just placed into the column you want to insert the
date into.

HTH

Rkr          
--

                   \|||/
                   /'^'\
                  ( 0 0 )
--------------oOOO--(_)--OOOo--------------
. Reid Roman                              .
. Programmer / Analyst                    .
. TVisualBasic := Class(None)             .
. May the Source be With You              .
-------------------------------------------
. Auto-By-Tel (http://www.autobytel.com)  .
. Irvine, CA U.S.A                        .
. E-Mail : rkroman (at) home (dot) com    .
-------------------------------------------

Re:MS SQL 6.5 Stored procedure


Many thank for replay,
I made mistake when I (some how) wrote 'Stored procedure', I just looking for
trigger (what is more less same in MSSQL) or something like that.
Accidentally, I found somewhere in MSSQL help that I could use GetDate()
function as default value for my datetime field, what is exactly what I looking
for.
That was little surprise for me, because I didn't except that function call
could be a default value. So, my next question will be 'Where is a limit ?', or
is GetDate() exception ?

Sinisa

P.S. Excuse me for my English

Quote
Reid Roman wrote:
> "Sini1a Vuleta" wrote:

> > I am a new with MS SQL and reading documentation I didn't found way how to
> > implement stored procedure which will set present date-time (GetDate()) in
> > some record datetime field on insert event (primary key is not autoinc - I
> > solve probem with autoinc). Something like this Interbase trigger:

> > Triggers on Table SOMETABLE:
> > TRIGGERNAME, Sequence: 0, Type: BEFORE INSERT, Active
> > as begin  new.SOMEDATE = "now"; end

> > Help, please !

> > Sinisa

> If this were not a TRIGGER and done as a normal Stored procedure using
> MS SQL
> it would be something like this:

> PROCEDURE Add_Customer
>           @Customer_ID_int INT,
>           @Customer_First_Name_vch VARCHAR(50),
>           @Customer_Last_Name_vch VARCHAR(50),
>           @Customer_Email_Address_vch VARCHAR(50

> AS

> INSERT INTO Customer
>      VALUES (
>              @Customer_ID_int,
>              @Customer_First_Name_vch,
>              @Customer_Last_Name_vch,
>              @Customer_Email_Address_vch,
>              GetDate()
>             )

> GO

> The GetDate() call is just placed into the column you want to insert the
> date into.

> HTH

> Rkr
> --

>                    \|||/
>                    /'^'\
>                   ( 0 0 )
> --------------oOOO--(_)--OOOo--------------
> . Reid Roman                              .
> . Programmer / Analyst                    .
> . TVisualBasic := Class(None)             .
> . May the Source be With You              .
> -------------------------------------------
> . Auto-By-Tel (http://www.autobytel.com)  .
> . Irvine, CA U.S.A                        .
> . E-Mail : rkroman (at) home (dot) com    .
> -------------------------------------------

Re:MS SQL 6.5 Stored procedure


Quote
Sinisa Vuleta wrote:

> Many thank for replay,
> I made mistake when I (some how) wrote 'Stored procedure', I just looking for
> trigger (what is more less same in MSSQL) or something like that.
> Accidentally, I found somewhere in MSSQL help that I could use GetDate()
> function as default value for my datetime field, what is exactly what I looking
> for.
> That was little surprise for me, because I didn't except that function call
> could be a default value. So, my next question will be 'Where is a limit ?', or
> is GetDate() exception ?

Hmm...  

I don't know quite what you mean "The Limit" or "Exception" ...

Exception to the rule??

But as far as the TRIGGER -vs- Stored Procedure concept, a TRIGGER is
essentially a system stored procedure, so wherever you place a
"GetDate()" fill a column's value it will be appropriate

Rkr

                   \|||/
                   /'^'\
                  ( 0 0 )
--------------oOOO--(_)--OOOo--------------
. Reid Roman                              .
. Programmer / Analyst                    .
. TVisualBasic := Class(None)             .
. May the Source be With You              .
-------------------------------------------
. Auto-By-Tel (http://www.autobytel.com)  .
. Irvine, CA U.S.A                        .
. E-Mail : rkroman (at) home (dot) com    .
-------------------------------------------

Re:MS SQL 6.5 Stored procedure


I newbie with MS SQL and I was supprised that function could be default
value. Today I found in help that all nilic (functions without input
parameters) could be used like default value (GetDate(), User_ID, etc...).
Is this true and for user defined functions ?

Sinisa

Other Threads