Solved

Msg 402 Error in Code SQL in Sql Server 2005 Enviroment

Posted on 2008-06-09
3
2,190 Views
Last Modified: 2010-04-21
Am getting the following error message and do not understand why.
Msg 402, Level 16, State 1, Line 21 - The data types varchar and varchar are incompatible in the modulo operator.  I have validated part of the code as indicated below.  I am new to this enviroment so any explanation as to why the code is worng is greatly apprecieated

Code being used -
declare @tabtemp table (i int identity, sl_effected_user_id varchar(20)null)
declare @rows int
declare @var1 as varchar(20)
declare @query as varchar(8000)

insert into @tabtemp
select sl_effected_user_id
from table1

----------------------------I have validated to here and all is good

Select @rows = @@ROWCOUNT
While @rows >0

Begin

Select @var1 = sl_effected_user_id
from @tabtemp WHERE i = @Rows

set @query = '
insert into table3

select sl_id, sys_creation_date, operator_id, application_id, sl_app_id,
sl_effected_environment, sl_effected_profile_id, sl_effected_user_id,
sl_location, sl_event_description
from table2
where sl_effected_user_id like ('% +@var1+ ')
'
print @query

SET @Rows = @Rows -1
exec (@query)
END
0
Comment
Question by:frogman22
3 Comments
 
LVL 60

Assisted Solution

by:chapmandew
chapmandew earned 100 total points
ID: 21746074
gin

Select @var1 = sl_effected_user_id
from @tabtemp WHERE i = @Rows

set @query = '
insert into table3

select sl_id, sys_creation_date, operator_id, application_id, sl_app_id,
sl_effected_environment, sl_effected_profile_id, sl_effected_user_id,
sl_location, sl_event_description
from table2
where sl_effected_user_id like (%' +@var1+ ')'
print @query

SET @Rows = @Rows -1
exec (@query)
END
Tags:
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 400 total points
ID: 21746099
set @query = '
insert into table3

select sl_id, sys_creation_date, operator_id, application_id, sl_app_id,
sl_effected_environment, sl_effected_profile_id, sl_effected_user_id,
sl_location, sl_event_description
from table2
where sl_effected_user_id like '+'''% '+@var1+ ''''
0
 

Author Closing Comment

by:frogman22
ID: 31465532
the first solution fixed the % issue but when added caused a new error.  The second solution has fixed the problem.  Thanks for all the help and rapid response
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question