I have the following SP
create procedure dbo.i114_get_next_oid
as
begin
DECLARE @id as integer
DECLARE @num_ids as integer
EXEC dbo.i144_get_ids 2, 1, @id output, @num_ids output
SELECT @id as N'@base_id'
end
go
which is pulling an application-managed UID for a SQL insert by calling
exec dbo.i114_get_next_oid
Our application requirements have grown somewhat, and I'm wondering how I could use 'exec dbo.i114_get_next_oid' as a Computed Column Specification? Or a contraint? Scratching my head on this. THanks!
Here is the table schema
CREATE TABLE [dbo].[TBL_VITAL_EVENTS](
[Location_ID] [uniqueidentifier] NOT NULL,
[Event_ID] [uniqueidentifier] NOT NULL,
[OBJECTID] [uniqueidentifier] NULL,
CONSTRAINT [PK_TBL_VITAL_EVENTS] PRIMARY KEY CLUSTERED
(
[Event_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[TBL_VITAL_EVENTS] WITH CHECK ADD CONSTRAINT [FK_TBL_VITAL_EVENTS_GRSM_VITAL_SIGNS_PLOTS] FOREIGN KEY([Location_ID])
REFERENCES [dbo].[GRSM_VITAL_SIGNS_PLOTS] ([Location_ID])
GO
ALTER TABLE [dbo].[TBL_VITAL_EVENTS] CHECK CONSTRAINT [FK_TBL_VITAL_EVENTS_GRSM_VITAL_SIGNS_PLOTS]
GO
ALTER TABLE [dbo].[TBL_VITAL_EVENTS] ADD CONSTRAINT [DF_TBL_VITAL_EVENTS_Event_ID] DEFAULT (newsequentialid()) FOR [Event_ID]
GO
Currently, the application (GIS) populates the OBJECTID field through C# hard-coded in the application. We need to circumvent that logic as we are performing some additional operations on the inserted data while it resides in the adds table before it is inserted into the business table. So our requirement now is to either use the SP or some other method as a trigger, or a computed column specification, to populate the OID field sequentially using the next OID. The next OID is managed by the function "dbo.i144_get_ids", and due to the architecture of the application, unfortunately, we are not able to NOT use that SP on inserts. This is sourced from the vendor documentation here: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/in_SQL_Server/006z00000017000000/
You can make a column from a function using CROSS APPLY
. You don't mention what your table looks like or your query for this, so here's a scenario. If you can rewrite your SP to be a TVF instead, or just use the function instead of the SP, you can use:
SELECT t.<fields>, fun.UID
FROM MyTable t
CROSS APPLY dbo.MyFunction(t.Inputfield, t.inputfield2) as Fun