dkocheno
asked on
Invalid length parameter passed to the substring function.
the following query runs fine with the code commented out of the group by, but errors with it - how can I get around it?
select DayID = convert(numeric,replace(ca st(year(Ev entTime) as varchar(4))+ '/' + right('0' + cast(month(EventTime) as
varchar(2)), 2) + '/' + right('0' + cast(day(EventTime) as varchar(2)), 2) ,'/','')),
CorpCode,
CustomerNumber,
UserID,
Application,
RequestedURI,
ImageName = substring(WE.RequestedURI, patindex(' %[_]%',WE. RequestedU RI)+1, CHARINDEX('_',WE.Requested URI, CHARINDEX('_',WE.Requested URI)+1)-1- patindex(' %[_]%',WE. RequestedU RI))
-- Requests = count(*)
from TDTRANSFER..WebEventsBacku p WE with (nolock)
join URLS with (nolock)
on WE.RequestedURI like URL
where WE.ReferrerURI like '%ene_categories%' or WE.ReferrerURI like '%ene_results%'
group by convert(numeric,replace(ca st(year(Ev entTime) as varchar(4))+ '/' + right('0' + cast(month(EventTime) as
varchar(2)), 2) + '/' + right('0' + cast(day(EventTime) as varchar(2)), 2) ,'/','')), CorpCode,
CustomerNumber, UserID, Application,RequestedURI-- , substring(WE.RequestedURI, patindex(' %[_]%',WE. RequestedU RI)+1, CHARINDEX('_',WE.Requested URI, CHARINDEX('_',WE.Requested URI)+1)-1- patindex(' %[_]%',WE. RequestedU RI))
select DayID = convert(numeric,replace(ca
varchar(2)), 2) + '/' + right('0' + cast(day(EventTime) as varchar(2)), 2) ,'/','')),
CorpCode,
CustomerNumber,
UserID,
Application,
RequestedURI,
ImageName = substring(WE.RequestedURI,
-- Requests = count(*)
from TDTRANSFER..WebEventsBacku
join URLS with (nolock)
on WE.RequestedURI like URL
where WE.ReferrerURI like '%ene_categories%' or WE.ReferrerURI like '%ene_results%'
group by convert(numeric,replace(ca
varchar(2)), 2) + '/' + right('0' + cast(day(EventTime) as varchar(2)), 2) ,'/','')), CorpCode,
CustomerNumber, UserID, Application,RequestedURI--
ASKER
Requests are commented out......If I add that I have to use the group by which is why it errors out
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To test that, sun this:
select RequestedURI
from TDTRANSFER..WebEventsBacku p WE with (nolock)
join URLS with (nolock)
on WE.RequestedURI like URL
where WE.ReferrerURI like '%ene_categories%' or WE.ReferrerURI like '%ene_results%'
AND CHARINDEX('_',WE.Requested URI, CHARINDEX('_',WE.Requested URI)+1)-1- patindex(' %[_]%',WE. RequestedU RI) < 1
hth,
Landy
select RequestedURI
from TDTRANSFER..WebEventsBacku
join URLS with (nolock)
on WE.RequestedURI like URL
where WE.ReferrerURI like '%ene_categories%' or WE.ReferrerURI like '%ene_results%'
AND CHARINDEX('_',WE.Requested
hth,
Landy
You don't have a comma before Requests = count(*). Also, you should count one of the fields in the Group By clause.
Try ", Request = count(UserID)"