Well I've done some reading but I think I may be missing something here.
I am trying to pass an optional argument to a sproc that will select
with a "Where like" clause on an integer data type. I basically need to
select All id's or only One id from the customer table. Here's what I
have so far, but it's not working:
create proc sp_sproc
@s2date datetime,
@e2date datetime,
@sdate datetime,
@edate datetime,
@customerid int = '%',
@n char(1) = '%'
as
set nocount on
select
count(distinct c.customerid) as TCli
from customer c
where
customername not like 'zz%'
and Customerid like @customerid
and exists (
Select * from assignviewcust s
where c.customerid = s.customerid
and (s.Perf = 'PL'
or s.Perf = 'CO'
or s.Perf = 'RMVJ')
and
(s.startdate is not null
or s.enddate is not null)
and
((s.startdate <= @eDate and
s.enddate >= @eDate)
or (s.startdate <= @sDate and
s.enddate >= @sDate)
or (s.startdate >= @sDate and
s.enddate <= @eDate))
and s.skillcode like @n + '%'
)
the exec would be:
exed sp_sproc @s2date, @e2date, @sdate, @edate, (optional customerid),
(optional skillcode)
I get an error like so:
Syntax error converting the varchar value '%' to a column of data type int.
I can see how this would need to be an INT datatype and not a string,
but then how do I use a wildcard for an INT type? Maybe I am going
about this totally wrong?
I appreciate any help you may have.
Thanks,
Greg
I am trying to pass an optional argument to a sproc that will select
with a "Where like" clause on an integer data type. I basically need to
select All id's or only One id from the customer table. Here's what I
have so far, but it's not working:
create proc sp_sproc
@s2date datetime,
@e2date datetime,
@sdate datetime,
@edate datetime,
@customerid int = '%',
@n char(1) = '%'
as
set nocount on
select
count(distinct c.customerid) as TCli
from customer c
where
customername not like 'zz%'
and Customerid like @customerid
and exists (
Select * from assignviewcust s
where c.customerid = s.customerid
and (s.Perf = 'PL'
or s.Perf = 'CO'
or s.Perf = 'RMVJ')
and
(s.startdate is not null
or s.enddate is not null)
and
((s.startdate <= @eDate and
s.enddate >= @eDate)
or (s.startdate <= @sDate and
s.enddate >= @sDate)
or (s.startdate >= @sDate and
s.enddate <= @eDate))
and s.skillcode like @n + '%'
)
the exec would be:
exed sp_sproc @s2date, @e2date, @sdate, @edate, (optional customerid),
(optional skillcode)
I get an error like so:
Syntax error converting the varchar value '%' to a column of data type int.
I can see how this would need to be an INT datatype and not a string,
but then how do I use a wildcard for an INT type? Maybe I am going
about this totally wrong?
I appreciate any help you may have.
Thanks,
Greg
Comment