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 |
|
sinjin67
Yak Posting Veteran
53 Posts |
Posted - 2008-05-05 : 18:27:42
|
| Everything works except for the select portion, I cant put my finger on what is wrong with this.. I included the trigger and error..If one can show what I did wrong that would be great..Thanx..SET QUOTED_IDENTIFIER ONGOALTER TRIGGER [dbo].[arcit] ON [dbo].[active] AFTER UPDATE asbegin begin tran SET IDENTITY_INSERT Archive ON INSERT INTO Archive() SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'archive' order by ordinal_position from Inserted i inner join deleted d on d.grid = i.grid inner join [Active] a on a.grid = i.grid WHERE i.arc = 1 and isNull(d.arc,0) != 1 DELETE FROM a from Inserted i inner join deleted d on d.grid = i.grid inner join [Active] a on a.grid = i.grid WHERE i.arc = 1 and isNull(d.arc,0) != 1 commit tranendError MessageMsg 156, Level 15, State 1, Procedure arcit, Line 10Incorrect syntax near the keyword 'from'. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-05-05 : 18:30:45
|
| Your code does not make sense. What are you intending to do with INFORMATION_SCHEMA.TABLES?Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-06 : 01:11:34
|
quote: Originally posted by sinjin67 Everything works except for the select portion, I cant put my finger on what is wrong with this.. I included the trigger and error..If one can show what I did wrong that would be great..Thanx..SET QUOTED_IDENTIFIER ONGOALTER TRIGGER [dbo].[arcit] ON [dbo].[active] AFTER UPDATE asbegin begin tran SET IDENTITY_INSERT Archive ON INSERT INTO Archive() SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'archive' order by ordinal_position from Inserted i inner join deleted d on d.grid = i.grid inner join [Active] a on a.grid = i.grid WHERE i.arc = 1 and isNull(d.arc,0) != 1 DELETE FROM a from Inserted i inner join deleted d on d.grid = i.grid inner join [Active] a on a.grid = i.grid WHERE i.arc = 1 and isNull(d.arc,0) != 1 commit tranendError MessageMsg 156, Level 15, State 1, Procedure arcit, Line 10Incorrect syntax near the keyword 'from'.
Your SELECT clause is wrong. You have two from statements. Can i ask what is your requirement? |
 |
|
|
sinjin67
Yak Posting Veteran
53 Posts |
Posted - 2008-05-06 : 14:07:03
|
| I am just trying to get the trigger to grab all the columnnames instead of typing it. In my test triggerI have used Select (name, com, address) its just when their are lots to type I was thinkingtheir has to be way to select everything for that recordand send it to the archive then delete the original record. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-05-06 : 14:10:16
|
| You can not do that without dynamic SQL. It would not be advisable in a trigger though.Stop being lazy and type out the columns. You can easily script them from Management Studio or Query Analyzer.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
sinjin67
Yak Posting Veteran
53 Posts |
Posted - 2008-05-06 : 18:04:16
|
| Guys, I am just doing my best to learn..Thanx for the input.. |
 |
|
|
|
|
|
|
|