Why REPLACE query is taking so much time in SQL Server 2008 -
i have sql query converts date time 106 format , after replacing blank space -
takes time 4 min while executing . example follows
replace(convert(varchar,getdate(),106),' ','-') ddate
output 19-feb-2015
without replace query taking 0 second
is there way custom format dates mentioned above ? understood replace
compare collection of result items. should not take 4 min replace 100 200 data.
any thoughts?
query
select top(isnull(100,'10000')) fd.flight 'select' ,fd.filename ,isnull(fd.refno, 'flt-' + convert(varchar, fd.flid)) 'flightid' ,fd.registration ,isnull(fd.flightnumber, '') flightnumber **,replace(convert(varchar,fd.tkd,106),' ','-') todate** ,fd.togmt **,replace(convert(varchar,fd.lkd,106),' ','-') lddate** ,fd.ldgmt ,fd.origin ,fd.destination ,fd.pilot ,fd.copilot **,replace(convert(varchar,fd.dumpdate,106),' ','-') ddate** ,fd.username ,fd.flightcount ,fd.acvariation dbo.vw_flightdetails fd left join [dbo].flightremark rm on rm.flightid = fd.flid 1=1 order fd.tkd desc ,fd.togmt desc
bold area problem facing
it's hard tell what's happening here, can try this:
select <all _other_ columns>, isnull(x.refno, 'flt-' + convert(varchar, x.flid)) flightid, replace(convert(varchar, x.tkd, 106),' ','-') todate, replace(convert(varchar, x.lkd, 106),' ','-') lddate, replace(convert(varchar, x.dumpdate, 106),' ','-') ddate, ( select top (isnull(100,'10000')) fd.flight 'select' ,fd.filename ,fd.refno, ,fd.flid ,fd.registration ,isnull(fd.flightnumber, '') flightnumber ,fd.tkd ,fd.togmt ,fd.lkd ,fd.ldgmt ,fd.origin ,fd.destination ,fd.pilot ,fd.copilot ,fd.dumpdate ,fd.username ,fd.flightcount ,fd.acvariation dbo.vw_flightdetails fd left join [dbo].flightremark rm on rm.flightid = fd.flid 1=1 order fd.tkd desc ,fd.togmt desc ) x
basically, bury query subquery, format dates on resulting rows. suspect happening because of top() statement... processing many more rows replace needs to.
Comments
Post a Comment