Solved

Msg 402 Error in Code SQL in Sql Server 2005 Enviroment

Posted on 2008-06-09
3
2,175 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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now