Invalid Object Error on Insert after read of same table
I am trying to insert data into a table based off what is already in the table. I read the table to get the number of records inserted for a certian month and then insert information based off if it is more or less than ten. After I read the table it throws an invalid object name when I try to do that insert. It's not an invalid object as it just read the table. If this is a permissions error how do I correct it? My code is below. Thanks,
Jason
declare @email VARCHAR(75),
@seminarNumber INT,
@isValidEmail BIT,
@monthlyTotal INT,
@statusCode INT
set @email = 'email@domain.com'
set @seminarNumber = '12345'
set @isValidEmail = dbo.RegexMatch('^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|(开发者_Go百科[a-zA-Z]{2,3})|(aero|coop|info|museum|name))$',@email)
if @isValidEmail = 1
begin
SELECT @monthlyTotal = count(mailid)
from Email_Tracking
where emailaddress = @email
and year(datesent) = year(getdate())
and month(datesent) = month(getdate())
if @monthlyTotal > 10
begin
set @statusCode = 1
end
else
begin
set @statusCode = 2
end
end
else
begin
set @statusCode = 3
end
if @statusCode = 1
begin
insert Email_Tracking ('seminarNumber','email','reasonNotSent')
values(@seminarNumber,@email,'Maximum surveys for the month have already been sent')
end
else if @statusCode = 2
begin
insert Email_Tracking ('seminarNumber','email','datesent')
values(@seminarNumber,@email,getdate())
end
else if @statusCode = 3
begin
insertEmail_Tracking ('seminarNumber','email','reasonNotSent')
values(@seminarNumber,@email,'Email address missing or invalid')
end
print @statusCode
try removing quotes from column names. so for eg:
insert Email_Tracking (seminarNumber,email,reasonNotSent)
values(@seminarNumber,@email,'Email address missing or invalid')
精彩评论