Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Insert with select

Author  Topic 

rkruis
Starting Member

28 Posts

Posted - 2012-06-08 : 14:02:43
How do I get the select statement to execute after each insert?

Basically when the insert statement executes, I want it to add a new parent_label that is one higher than the last insert.

What I get, is it adds the same parent_label as the first. It isn't taking into consideration the last record inserted.


insert parenttmp (parent_label, parent_code)
select BrandUpload.ParentCompany,
( dbo.FunctionGetNextHighestLabel )
from BrandUpload



*** FunctionGetNextHighestLabel ***
var = select parenttmp.parent_label from parenttmp PLUS some alpha chars.

EX: 09FF


Thanks for any help.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-08 : 14:41:52
why should you use a function for this? isnt it enough to use a custom sequence based on identity column like below?

http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

rkruis
Starting Member

28 Posts

Posted - 2012-06-08 : 15:29:18
The function was already written, so I wanted to use it instead of creating a trigger.

If a trigger is the easiest way to go, then I will just implement that.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-08 : 16:20:20
quote:
Originally posted by rkruis

The function was already written, so I wanted to use it instead of creating a trigger.

If a trigger is the easiest way to go, then I will just implement that.


I never suggested trigger

I was suggesting use of computed column to generate sequence as link explains!

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -