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.
| Author |
Topic |
|
Lucky
Starting Member
10 Posts |
Posted - 2008-08-01 : 02:24:12
|
| Hi Dears, can u plz help me out urgently, Actually I am passing @empno to > c:\Output.vbs' but its not creating, can u plz help me out.there is no error in Trigger.many thanks,set ANSI_NULLS ONset QUOTED_IDENTIFIER ONGOALTER TRIGGER [dbo].[t_Term]ON [dbo].[EMTER]FOR UPDATEASDECLARE @tdate1 DATETIMEDECLARE @tdate2 DATETIMEDECLARE @empno INTSET @tdate1=(select ter_dated from INSERTED)SET @tdate2=(select ter_dated from DELETED)IF (@tdate1 <> @tdate2)BEGIN TRYSET @empno=(SELECT det_numbera FROM Inserted) DECLARE @cmd sysname, @var sysnameSET @var = @empnoSET @cmd = 'echo ' + @var + ' > c:\Output.vbs'EXEC master..xp_cmdshell @cmd--INSERT INTO testEmp VALUES(@empno)-- select * from testempEND TRYBEGIN CATCHSELECT ERROR_NUMBER() as ErrorNumber,ERROR_MESSAGE() as ErrorMessage;END CATCH______________________________________________________________________________________"We can be Knowledgeable with other mens Knowledge, but we can't be wise with other mens wisdom" |
|
|
Lucky
Starting Member
10 Posts |
Posted - 2008-08-01 : 02:33:13
|
| HI, I am running this TSQl and its working fine, but I don't know why its not creating file through TRIGGER,Declare @empno intset @empno = '001234'DECLARE @cmd sysname, @var sysnameSET @var = cast(@empno as varchar(255))SET @cmd = 'echo ' + @var + ' > c:\Output.vbs'EXEC master..xp_cmdshell @cmd______________________________________________________________________________________"We can be Knowledgeable with other mens Knowledge, but we can't be wise with other mens wisdom" |
 |
|
|
pootle_flump
1064 Posts |
Posted - 2008-08-01 : 04:00:53
|
1) Your error handling is wrong - a trigger cannot return a result set. Stick this in your catch:RAISERROR(ERROR_MESSAGE(), 16, 1) 2) Also - your code assumes that only one row at a time will be affected - it is not coded correctly to deal with set based changes. This is a common trigger error.If 1 does not change anything,try inserting the return from EXEC master..xp_cmdshell @cmd into a table and interrogate that. I would include the value of @cmd too to help your debugging. |
 |
|
|
pootle_flump
1064 Posts |
Posted - 2008-08-01 : 04:45:07
|
| Actually - sorry - that is not valid syntax - you can't reference ERROR_MESSAGE() directly with RAISERROR. Just comment out the TRY...CATCH for now instead - that way you will receive the errors. |
 |
|
|
Lucky
Starting Member
10 Posts |
Posted - 2008-08-04 : 23:36:03
|
| HI,SET @cmd = 'echo ' + CAST(@empno AS VARCHAR) + '\\abc000vfs002\IT$\\Output.vbs' I am just creating OUTPUT file on the network with the above command, I can create on Local drive but can't get OUTPUT.vbs on the network can u hlep me please ?????______________________________________________________________________________________"We can be Knowledgeable with other mens Knowledge, but we can't be wise with other mens wisdom" |
 |
|
|
|
|
|
|
|