Question : Insert Trigger stoping new data

I have an insert trigger on one of my database tables (see attatched trigger) It calls a stored procedure (see other attatched)

We have a small vb.net app that pulls the data to insert into the table from an external webserver.

For some reason when the insert trigger is set on the table, no new rows get added. When i remove the trigger new rows are added as soon as i run the .net app.

It seems that the trigger is stopping the new rows from being added.

Can anybody suggest why?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
create trigger tg_webenquiries
on webenquiries
after insert
as
declare
	@Campaign as nvarchar(50),
	@Telephone as nvarchar(20),
	@Telephone2 as nvarchar(20),
	@Telephone3 as nvarchar(20),
	@Display as nvarchar(255),
	@Field3 as nvarchar(255),
	@Field4 as nvarchar(255),
	@Field5 as nvarchar(255),
	@Field6 as nvarchar(255)
select
	@Campaign = 'Doris Leads',
	@Telephone = Daytime_Telephone,
	@Telephone2 = Evening_Telephone,
	@Telephone3 = Mobile_Telephone,
	@Display = Title + ' ' + Initials + ' ' + Surname,
	@Field3 = '',
	@Field4 = '',
	@Field5 = '',
	@Field6 = WebEnquiryID
from INSERTED
exec dialler1..ImportDorisLeads
	@Campaign,
	@Telephone,
	@Telephone2,
	@Telephone3,
	@Display,
	@Field3,
	@Field4,
	@Field5,
	@Field6
GO
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
CREATE PROCEDURE ImportDorisLeads

	@Campaign as nvarchar(50),
	@Telephone as nvarchar(20),
	@Telephone2 as nvarchar(20),
	@Telephone3 as nvarchar(20),
	@Display as nvarchar(255),
	@Field3 as nvarchar(255),
	@Field4 as nvarchar(255),
	@Field5 as nvarchar(255),
	@Field6 as nvarchar(255)

AS

DECLARE @SearchResult as int
DECLARE @Sql1 AS NVARCHAR(2000)
DECLARE @Sql2 AS NVARCHAR(2000)
DECLARE @SQL3 AS NVARCHAR(2000)
DECLARE @1Out AS INT
DECLARE @2Out AS INT
DECLARE @3Out AS INT

--Remove any Invalid Characters from the Telephone Numbers
Set @Telephone = Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(
	Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(
	Replace(Replace(Replace(Replace(Replace(Replace(Replace(

	@Telephone, ' ' , ''), '!', ''), '"', ''), '£', ''), '$', '')
	, '%' , ''), '^', ''), '&', ''), '*', ''), '(', '')
	, ')' , ''), '-', ''), '_', ''), '=', ''), '+', '')
	, '[' , ''), ']', ''), '{', ''), '}', ''), ';', '')
	, ':' , ''), '''', ''), '@', ''), '~', ''), '#', '')
	, '\' , ''), '|', ''), ',', ''), '<', ''), '.', '')
	, '>' , ''), '/', ''), '?', ''), '`', ''), '¬', '')

	, 'a', ''), 'b', ''), 'c', ''), 'd', ''), 'e', ''), 'f', '')
	, 'g', ''), 'h', ''), 'i', ''), 'j', ''), 'k', ''), 'l', '')
	, 'm', ''), 'n', ''), 'o', ''), 'p', ''), 'q', ''), 'r', '')
	, 's', ''), 't', ''), 'u', ''), 'v', ''), 'w', ''), 'x', '')
	, 'y', ''), 'z', '')

	, 'A', ''), 'B', ''), 'C', ''), 'D', ''), 'E', ''), 'F', '')
	, 'G', ''), 'H', ''), 'I', ''), 'J', ''), 'K', ''), 'L', '')
	, 'M', ''), 'N', ''), 'O', ''), 'P', ''), 'Q', ''), 'R', '')
	, 'S', ''), 'T', ''), 'U', ''), 'V', ''), 'W', ''), 'X', '')
	, 'Y', ''), 'Z', '')

Set @Telephone2 = Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(
	Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(
	Replace(Replace(Replace(Replace(Replace(Replace(Replace(

	@Telephone2, ' ' , ''), '!', ''), '"', ''), '£', ''), '$', '')
	, '%' , ''), '^', ''), '&', ''), '*', ''), '(', '')
	, ')' , ''), '-', ''), '_', ''), '=', ''), '+', '')
	, '[' , ''), ']', ''), '{', ''), '}', ''), ';', '')
	, ':' , ''), '''', ''), '@', ''), '~', ''), '#', '')
	, '\' , ''), '|', ''), ',', ''), '<', ''), '.', '')
	, '>' , ''), '/', ''), '?', ''), '`', ''), '¬', '')

	, 'a', ''), 'b', ''), 'c', ''), 'd', ''), 'e', ''), 'f', '')
	, 'g', ''), 'h', ''), 'i', ''), 'j', ''), 'k', ''), 'l', '')
	, 'm', ''), 'n', ''), 'o', ''), 'p', ''), 'q', ''), 'r', '')
	, 's', ''), 't', ''), 'u', ''), 'v', ''), 'w', ''), 'x', '')
	, 'y', ''), 'z', '')

	, 'A', ''), 'B', ''), 'C', ''), 'D', ''), 'E', ''), 'F', '')
	, 'G', ''), 'H', ''), 'I', ''), 'J', ''), 'K', ''), 'L', '')
	, 'M', ''), 'N', ''), 'O', ''), 'P', ''), 'Q', ''), 'R', '')
	, 'S', ''), 'T', ''), 'U', ''), 'V', ''), 'W', ''), 'X', '')
	, 'Y', ''), 'Z', '')

Set @Telephone3 = Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(
	Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(
	Replace(Replace(Replace(Replace(Replace(Replace(Replace(

	@Telephone3, ' ' , ''), '!', ''), '"', ''), '£', ''), '$', '')
	, '%' , ''), '^', ''), '&', ''), '*', ''), '(', '')
	, ')' , ''), '-', ''), '_', ''), '=', ''), '+', '')
	, '[' , ''), ']', ''), '{', ''), '}', ''), ';', '')
	, ':' , ''), '''', ''), '@', ''), '~', ''), '#', '')
	, '\' , ''), '|', ''), ',', ''), '<', ''), '.', '')
	, '>' , ''), '/', ''), '?', ''), '`', ''), '¬', '')

	, 'a', ''), 'b', ''), 'c', ''), 'd', ''), 'e', ''), 'f', '')
	, 'g', ''), 'h', ''), 'i', ''), 'j', ''), 'k', ''), 'l', '')
	, 'm', ''), 'n', ''), 'o', ''), 'p', ''), 'q', ''), 'r', '')
	, 's', ''), 't', ''), 'u', ''), 'v', ''), 'w', ''), 'x', '')
	, 'y', ''), 'z', '')

	, 'A', ''), 'B', ''), 'C', ''), 'D', ''), 'E', ''), 'F', '')
	, 'G', ''), 'H', ''), 'I', ''), 'J', ''), 'K', ''), 'L', '')
	, 'M', ''), 'N', ''), 'O', ''), 'P', ''), 'Q', ''), 'R', '')
	, 'S', ''), 'T', ''), 'U', ''), 'V', ''), 'W', ''), 'X', '')
	, 'Y', ''), 'Z', '')

--Tests that the Numbers are more than 3 characters Long
IF LEN(@Telephone) < 3
BEGIN
	SET @Telephone = ''
END

IF LEN(@Telephone2) < 3
BEGIN
	SET @Telephone2 = ''
END

IF LEN(@Telephone3) < 3
BEGIN
	SET @Telephone3 = ''
END

--Tests to see if the Number starts with a 0, if not add it
IF LEN(@Telephone) = 10 AND LEFT(@Telephone,1) <> 0
BEGIN
	SET @Telephone = '0' + @Telephone
END

IF LEN(@Telephone2) = 10 AND LEFT(@Telephone2,1) <> 0
BEGIN
	SET @Telephone2 = '0' + @Telephone2
END

IF LEN(@Telephone2) = 10 AND LEFT(@Telephone2,1) <> 0
BEGIN
	SET @Telephone2 = '0' + @Telephone2
END

--Tests to see if number starts 44, if yes replace with 0
IF LEFT(@Telephone,2) = 44
BEGIN
	SET @Telephone = '0' + RIGHT(@Telephone,LEN(@Telephone)-2)
END

IF LEFT(@Telephone2,2) = 44
BEGIN
	SET @Telephone2 = '0' + RIGHT(@Telephone2,LEN(@Telephone2)-2)
END

IF LEFT(@Telephone3,2) = 44
BEGIN
	SET @Telephone3 = '0' + RIGHT(@Telephone3,LEN(@Telephone3)-2)
END

--Tests to see if any of the numbers match each other and removes appropriate if it does
IF @Telephone = @Telephone2
BEGIN
	SET @Telephone2 = ''
END

IF @Telephone = @Telephone3
BEGIN
	SET @Telephone = ''
END

IF @Telephone2 = @Telephone3
BEGIN
	SET @Telephone2 = ''
END

--Checks to see if the number is already in the dialler

SET @Sql1 = 'SELECT COUNT(*) FROM "' + @Campaign + '" WHERE Telephone = ''' + @Telephone + ''' OR Telephone2 = ''' + @Telephone + ''' OR Telephone3 = ''' + @Telephone + ''''
SET @Sql2 = 'SELECT COUNT(*) FROM "' + @Campaign + '" WHERE Telephone = ''' + @Telephone2 + ''' OR Telephone2 = ''' + @Telephone2 + ''' OR Telephone3 = ''' + @Telephone2 + ''''
SET @Sql3 = 'SELECT COUNT(*) FROM "' + @Campaign + '" WHERE Telephone = ''' + @Telephone3 + ''' OR Telephone2 = ''' + @Telephone3 + ''' OR Telephone3 = ''' + @Telephone3 + ''''

IF EXEC(@Sql1) <> 0
BEGIN
	SET @Telephone = ''
END

IF EXEC(@Sql2) <> 0
BEGIN
	SET @Telephone2 = ''
END

IF EXEC(@Sql3) <> 0
BEGIN
	SET @Telephone3 = ''
END


-- Check Barring Tables

EXEC BarredNumber_SearchForNumber @Telephone, @SearchResult output

IF @SearchResult = 1
BEGIN
	SET @Telephone = ''
	SET @SearchResult = 0
END

EXEC BarredNumber_SearchForNumber @Telephone2, @SearchResult output

IF @SearchResult = 1
BEGIN
	SET @Telephone2 = ''
	SET @SearchResult = 0
END

EXEC BarredNumber_SearchForNumber @Telephone3, @SearchResult output

IF @SearchResult = 1
BEGIN
	SET @Telephone3 = ''
END


--Write insert statament

DECLARE @StrSql AS NVARCHAR(2000)

Set @strSQL = 'INSERT INTO [' + @Campaign + '] (Telephone, Telephone2, Telephone3, Display, Field3, Field4, Field5, Field6, CallStatus, AccCode, TimesCalled, Valid, Code, LastNumberDialled) VALUES (' + Char(13) + Char(10) +
				'''' + @Telephone + ''', ''' + @Telephone2 + ''', ''' + @Telephone3 + ''', ''' + @Display + ''', ''' + @Field3 + ''', ''' + @Field4 + ''', ''' + @Field5 + ''', ''' + @Field6 + ''', '''', '''', 0, 1, '''', '''') '

EXEC(@StrSql)

Answer : Insert Trigger stoping new data

Hi again,

I'm a bit confused now.

Do you want to exclude reporting on userids which has been su'ed to?

In this case your report is indeed fine.

The "time_last_login" value of a user doesn't reflect su'ing to that user. Successful use of su resets the "unsuccessful_login_count" attribute only if the user's rlogin and login attributes are both set to false.

Of course the last login time of the user who issued "su" is recorded.

If you want to report on "su" use you will have to examine /var/adm/sulog. The drawback with that file is that the date is contained in mm/dd hh:mm format - that's not seconds since epoch, and there is no year!

Anyway - your script is a real nice thing - I can't see anything wrong with it!

wmp

 

Random Solutions  
 
programming4us programming4us