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 2008 Forums
 Other SQL Server 2008 Topics
 Msg 8124, Level 16, State 1, Procedure trigg1, Lin

Author  Topic 

srisha
Starting Member

38 Posts

Posted - 2013-05-23 : 05:32:09
ALTER TRIGGER [dbo].[trigg1]
ON [dbo].[OEORDH]
AFTER INSERT
AS
BEGIN
Update OEORDHO SEt oeordho.VALUE =
Rtrim(inserted.LOCATION) + (Select isnull(MAX(convert (int,(SUBSTRING(OEORDHO.VALUE,LEN(inserted.LOCATION)+1,
LEN(OEORDHO.VALUE))))),0) + 1
From OEORDHO Where
LEN(OEORDHO.VALUE)=LEN(inserted.LOCATION) and ISNUMERIC(SUBSTRING(OEORDHO.VALUE,4,LEN(OEORDHO.VALUE))) = 1
AND OPTFIELD='INVNO' AND LEFT(OEORDHO.VALUE,LEN(Rtrim(inserted.LOCATION)))=Rtrim(inserted.LOCATION))
From inserted Where OEORDHO.ORDUNIQ=inserted.ORDUNIQ AND OPTFIELD='INVNO'
END

Multiple columns are specified in an aggregated expression containing an outer reference. If an expression being aggregated contains an outer reference, then that outer reference must be the only column referenced in the expression.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-05-23 : 05:34:14
The given trigger code doesnt make much sense to me. You dont even have INSERTED table referred in query. Can i ask what you're trying to implement by the above code?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

srisha
Starting Member

38 Posts

Posted - 2013-05-23 : 05:38:51
To generate different document series on the basis of location chosen at different transaction screens .
This is planned by using the combination of ‘Location’ + Document Number (number with / without prefix).
------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs

[/quote]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-05-23 : 05:40:22
hmm...whats the purpose of doing this in a trigger then? Why not make the VALUE as a computed column instead?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

srisha
Starting Member

38 Posts

Posted - 2013-05-23 : 07:31:40
value is the one field name . Location wise record number


quote:
Originally posted by visakh16

hmm...whats the purpose of doing this in a trigger then? Why not make the VALUE as a computed column instead?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-05-23 : 07:36:01
ok...but didnt understand whats the problem in making it computed still?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -