473,395 Members | 1,639 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,395 software developers and data experts.

Is there a macro (as in C lang) like facility in SQL server 2000.

For the following table we've written an update trigger :

CREATE TABLE [dbo].[project] (
[project_id] [int] IDENTITY (1, 1) NOT NULL ,
[project_title] [udt_name2] NOT NULL ,
[project_description] [udt_desc1] NULL ,
[project_type_reference_id] [udt_ref_id] NULL ,
[requestor] [udt_n_user] NULL ,
[start_date] [udt_n_tsmp] NULL ,
[cost_center] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[status_reference_id] [udt_ref_id] NOT NULL ,
[group_id] [int] NOT NULL ,
[eta_date] [udt_n_tsmp] NULL ,
[percent_complete] [smallint] NULL ,
[status_note] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[rate_group_reference_id] [udt_ref_id] NULL ,
[spending_flag] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[tape_submitted_flag] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[on_air_flag] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[deleted_flag] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[create_datetime] [udt_n_tsmp] NULL ,
[create_user] [udt_n_user] NULL ,
[last_upd_datetime] [udt_n_tsmp] NULL ,
[last_upd_user] [udt_n_user] NULL
) ON [PRIMARY]
GO

The update trigger is like ....

CREATE TRIGGER trg_project_update ON [dbo].[project]
FOR UPDATE
AS
DECLARE @project_id INT,
@column_name char(50),
@old_value char(100) ,
@new_value char(100) ,
@create_datetime smalldatetime,
@create_user varchar(20)
select @project_id = i.project_id from inserted i

/* Action Reference ID = 3 Would translate to "Project Updated" in
reference table*/

insert into dbo.audit(table_id, column_id, key1,
action_reference_id,create_datetime,create_user) values( 'project',
'table', @project_id, 3,@create_datetime,@create_user)

if update( project_description)
begin
select @new_value = i.project_description from inserted i
select @old_value = d.project_description from deleted d
select @column_name = 'project_description'

insert into dbo.audit(table_id, column_id, key1, action_reference_id,
field_value_before, field_value_after )
values( 'project', @column_name, @project_id, 1, @old_value,
@new_value)
end

if update( project_title)
begin
select @new_value = i.project_title from inserted i
select @old_value = d.project_title from deleted d
select @column_name = 'project_title'

insert into dbo.audit(table_id, column_id, key1, action_reference_id,
field_value_before, field_value_after )
values( 'project', @column_name, @project_id, 1, @old_value,
@new_value)
end

if update( project_type_reference_id)
begin
select @new_value = i.project_type_reference_id from inserted i
select @old_value = d.project_type_reference_id from deleted d
select @column_name = 'project_type_reference_id'

insert into dbo.audit(table_id, column_id, key1, action_reference_id,
field_value_before, field_value_after )
values( 'project', @column_name, @project_id, 1, @old_value,
@new_value)
end

Here as you can see ..
We'll be writting a repeating set of codes with only a small
difference among each other.
So, is there any generic way in T-Sql so that we can write a
fuction/Macro in T-sql so that we just need to pass the column-name
and the table as its parameters.And later we can call the
function/macro instead of repeating the code.

Thanks!
Jul 20 '05 #1
0 1257

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ken Lindner | last post by:
I have a need to become familiar with SQL Server 2000 for work. Needless to say I am new to SQL Server any version, but not IT in general. My employer has provided me with the SQL Server 2000...
6
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used...
2
by: Jay Chan | last post by:
We have just installed a SQL Server 2000 (SP 3A) onto a computer that has Windows-2003 Server on it. Now, we cannot get access to that database server from other computers. Seem like this may be an...
2
by: Robert M. | last post by:
Information: Server A: SQL Server 2000 Enterprise Edition. OS is Windows 2003 Server Enterprise Edition. SQL Service pack is 3a. Member of domain ABCDomain. Server A is going to function as a...
0
by: Chris Halcrow | last post by:
Hi I've spent ALL DAY trying to re-install SQL Server 2000 on Windows XP. I continually get the error 'cannot configure server' just at the end of the installation. I've tried the following: ...
1
by: tskelley | last post by:
Something strange has happened on my computer. I am unable to link tables from SQL Server 2000. I have tried from Access 97 and 2000, but keep getting the error "The Microsoft Jet database engine...
1
by: bitchanger | last post by:
I have installed an SQL Server 2000 Developer Edition (SP4) on a computer that has Windows Server 2003 on it.The server is connected to the workgroup "WORK" and has no Active Directory. Now I...
1
by: doniravi | last post by:
hello sir... i m using sql server 2000 database and usig jsp to access it when accessig i am getting followig error java.sql.SQLException: Unable to connect. Invalid URL. i installed...
0
by: tamayi | last post by:
I have a problem (like most others posting issues on this forum :) ) I have a remote server running Windows XP SP2, with both SQL Server 2005 Express with Advanced Features and SQL 2000...
1
by: Eckhart | last post by:
How to fix error 207 in ms sql server 2000 with out applying SP4 service pack 4,on SQL SERVER 2000 wit sevice pack 3a - current environment ?
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.