Solved

SQL error

Posted on 2014-10-16
4
145 Views
Last Modified: 2014-10-16
Dear,

I am getting error for my web page which is showing below view.

Microsoft OLE DB Provider for SQL Server error '80004005'
Invalid length parameter passed to the RIGHT function.

There was no issue before and no recent change made. Screen shot of error is also attached.

Please help to solve it. I am using SQL 2005.

Thanks.,

VIEW

SELECT     dbo.shopcountries.countryname, dbo.orders.odate, dbo.orders.orderamount, dbo.orders.oemail, dbo.orders.oshipmethod, dbo.orders.oshipcost, 
                      dbo.orders.oshipname, dbo.orders.oshipcompany, dbo.orders.oshipemail, dbo.orders.oshipmethodtype, dbo.orders.oshipaddress, 
                      dbo.orders.oshiptown, dbo.orders.oshipzip, dbo.orders.oshipstate, dbo.orders.oshipcountry, dbo.orders.opaymethod, dbo.orders.oshipaddress2, 
                      dbo.s_ems_orders.emsid, dbo.s_ems_orders.ems_trackno, dbo.s_ems_orders.orderid, dbo.s_ems_orders.s_date, dbo.s_ems_orders.printed, 
                      dbo.s_ems_orders.Pickup_date, dbo.s_ems_orders.Pickup_time, dbo.s_ems_orders.recvd_for, dbo.s_ems_orders.emp_code, 
                      dbo.s_ems_orders.No_of_pcs, dbo.s_ems_orders.weight, dbo.s_ems_orders.nature_good_doc, dbo.s_ems_orders.nature_good_non_doc, 
                      dbo.s_ems_orders.breif_description, dbo.s_ems_orders.decl_inv_value, dbo.s_ems_orders.delivery_date, dbo.s_ems_orders.delivery_time, 
                      dbo.s_ems_orders.service_domestic, dbo.s_ems_orders.service_intl, dbo.s_ems_orders.payment_cash, dbo.s_ems_orders.payment_credit, 
                      dbo.s_ems_orders.ship_dom_exp, dbo.s_ems_orders.ship_intl_exp, dbo.s_ems_orders.ship_intra_ciity, dbo.s_ems_orders.ship_premium, 
                      dbo.s_ems_orders.ship_prepaid, dbo.s_ems_orders.ship_cod, dbo.s_ems_orders.credit_account, dbo.s_ems_orders.charges_basic, 
                      dbo.s_ems_orders.charges_insurance, dbo.s_ems_orders.charges_total, dbo.s_ems_orders.pickup_remarks, dbo.s_ems_orders.s_printed, 
                      dbo.s_ems_orders.s_system_id, dbo.s_ems_orders.service, dbo.s_ems_orders.userid, dbo.s_ems_orders.lastupdate, 
                      dbo.s_ems_orders.process_email_send, dbo.s_ems_orders.process_date, dbo.s_ems_orders.track_email, dbo.s_ems_orders.track_email_date, 
                      dbo.s_ems_orders.resend_process_email, dbo.s_ems_orders.disptach_req, dbo.s_ems_orders.dispatch_req_date, dbo.s_ems_orders.feedback_sent, 
                      dbo.s_ems_orders.feedback_sent_date, dbo.s_ems_orders.partner, dbo.s_ems_orders.partner_track, dbo.s_ems_orders.ship_status, 
                      dbo.orders.ophone, dbo.orders.ostatus, dbo.s_ems_orders.s_system_id AS chec_systemid, dbo.s_ems_orders.s_printed AS chec_printed, 
                      dbo.s_ems_orders.lastupdate AS Lastupdated, dbo.s_ems_orders.userid AS Usermade, dbo.s_ems_orders.service AS Servioceselected, 
                      dbo.s_ems_orders.process_email_send AS order_process, dbo.s_ems_orders.process_date AS order_process_date, 
                      dbo.s_ems_orders.resend_process_email AS track_resend, dbo.orders.ofirstname, dbo.orders.olastname, dbo.orders.oprocessed, 
                      dbo.s_ems_orders.track_email_date AS [tracking date sent], dbo.s_ems_orders.track_email AS [tracking email], 
                      dbo.s_ems_orders.dispatch_req_date AS [EMS req date], dbo.s_ems_orders.disptach_req AS [EMS dispatch req], 
                      RIGHT(dbo.s_ems_orders.ems_trackno, LEN(dbo.s_ems_orders.ems_trackno) - 4) AS Skynet_track, 
                      dbo.s_ems_orders.feedback_sent_date AS d_feedback, dbo.s_ems_orders.feedback_sent AS feedback, dbo.s_skynet_mapping.partner_url, 
                      dbo.s_ems_orders.ship_status AS shipping_status, dbo.s_ems_orders.shipper_remarks, dbo.s_ems_orders.customer_remarks
FROM         dbo.s_skynet_mapping RIGHT OUTER JOIN
                      dbo.s_ems_orders ON dbo.s_skynet_mapping.partner = dbo.s_ems_orders.partner LEFT OUTER JOIN
                      dbo.shopcountries RIGHT OUTER JOIN
                      dbo.orders ON dbo.shopcountries.country = dbo.orders.oshipcountry ON dbo.s_ems_orders.orderid = dbo.orders.orderid
WHERE     (dbo.s_ems_orders.service = 'SKYNET')

Open in new window

2014-10-16-20-45-21.jpg
0
Comment
Question by:NickHoward
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40385237
Most probably the issue is with data can you check if you have the column value less than 4 chars i.e.

select  ems_trackno
from dbo.s_ems_orders
where LEN(dbo.s_ems_orders.ems_trackno) <4
0
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40385240
If there is those less than 4 you can use something like this :

SELECT     dbo.shopcountries.countryname, dbo.orders.odate, dbo.orders.orderamount, dbo.orders.oemail, dbo.orders.oshipmethod, dbo.orders.oshipcost, 
                      dbo.orders.oshipname, dbo.orders.oshipcompany, dbo.orders.oshipemail, dbo.orders.oshipmethodtype, dbo.orders.oshipaddress, 
                      dbo.orders.oshiptown, dbo.orders.oshipzip, dbo.orders.oshipstate, dbo.orders.oshipcountry, dbo.orders.opaymethod, dbo.orders.oshipaddress2, 
                      dbo.s_ems_orders.emsid, dbo.s_ems_orders.ems_trackno, dbo.s_ems_orders.orderid, dbo.s_ems_orders.s_date, dbo.s_ems_orders.printed, 
                      dbo.s_ems_orders.Pickup_date, dbo.s_ems_orders.Pickup_time, dbo.s_ems_orders.recvd_for, dbo.s_ems_orders.emp_code, 
                      dbo.s_ems_orders.No_of_pcs, dbo.s_ems_orders.weight, dbo.s_ems_orders.nature_good_doc, dbo.s_ems_orders.nature_good_non_doc, 
                      dbo.s_ems_orders.breif_description, dbo.s_ems_orders.decl_inv_value, dbo.s_ems_orders.delivery_date, dbo.s_ems_orders.delivery_time, 
                      dbo.s_ems_orders.service_domestic, dbo.s_ems_orders.service_intl, dbo.s_ems_orders.payment_cash, dbo.s_ems_orders.payment_credit, 
                      dbo.s_ems_orders.ship_dom_exp, dbo.s_ems_orders.ship_intl_exp, dbo.s_ems_orders.ship_intra_ciity, dbo.s_ems_orders.ship_premium, 
                      dbo.s_ems_orders.ship_prepaid, dbo.s_ems_orders.ship_cod, dbo.s_ems_orders.credit_account, dbo.s_ems_orders.charges_basic, 
                      dbo.s_ems_orders.charges_insurance, dbo.s_ems_orders.charges_total, dbo.s_ems_orders.pickup_remarks, dbo.s_ems_orders.s_printed, 
                      dbo.s_ems_orders.s_system_id, dbo.s_ems_orders.service, dbo.s_ems_orders.userid, dbo.s_ems_orders.lastupdate,
                      dbo.s_ems_orders.process_email_send, dbo.s_ems_orders.process_date, dbo.s_ems_orders.track_email, dbo.s_ems_orders.track_email_date, 
                      dbo.s_ems_orders.resend_process_email, dbo.s_ems_orders.disptach_req, dbo.s_ems_orders.dispatch_req_date, dbo.s_ems_orders.feedback_sent, 
                      dbo.s_ems_orders.feedback_sent_date, dbo.s_ems_orders.partner, dbo.s_ems_orders.partner_track, dbo.s_ems_orders.ship_status, 
                      dbo.orders.ophone, dbo.orders.ostatus, dbo.s_ems_orders.s_system_id AS chec_systemid, dbo.s_ems_orders.s_printed AS chec_printed, 
                      dbo.s_ems_orders.lastupdate AS Lastupdated, dbo.s_ems_orders.userid AS Usermade, dbo.s_ems_orders.service AS Servioceselected, 
                      dbo.s_ems_orders.process_email_send AS order_process, dbo.s_ems_orders.process_date AS order_process_date, 
                      dbo.s_ems_orders.resend_process_email AS track_resend, dbo.orders.ofirstname, dbo.orders.olastname, dbo.orders.oprocessed, 
                      dbo.s_ems_orders.track_email_date AS [tracking date sent], dbo.s_ems_orders.track_email AS [tracking email], 
                      dbo.s_ems_orders.dispatch_req_date AS [EMS req date], dbo.s_ems_orders.disptach_req AS [EMS dispatch req], 
                      RIGHT(dbo.s_ems_orders.ems_trackno, LEN(dbo.s_ems_orders.ems_trackno) - case when LEN(dbo.s_ems_orders.ems_trackno) - 4 >= 0 then LEN(dbo.s_ems_orders.ems_trackno) - 4 else 0 end ) AS Skynet_track, 
                      dbo.s_ems_orders.feedback_sent_date AS d_feedback, dbo.s_ems_orders.feedback_sent AS feedback, dbo.s_skynet_mapping.partner_url, 
                      dbo.s_ems_orders.ship_status AS shipping_status, dbo.s_ems_orders.shipper_remarks, dbo.s_ems_orders.customer_remarks
FROM         dbo.s_skynet_mapping RIGHT OUTER JOIN
                      dbo.s_ems_orders ON dbo.s_skynet_mapping.partner = dbo.s_ems_orders.partner LEFT OUTER JOIN
                      dbo.shopcountries RIGHT OUTER JOIN
                      dbo.orders ON dbo.shopcountries.country = dbo.orders.oshipcountry ON dbo.s_ems_orders.orderid = dbo.orders.orderid
WHERE     (dbo.s_ems_orders.service = 'SKYNET')

Open in new window

0
 

Author Comment

by:NickHoward
ID: 40385242
Yeah I already spotted out and this was the reason for error. Any way I can avoid this in future?
0
 
LVL 15

Accepted Solution

by:
Haris Djulic earned 500 total points
ID: 40385246
I posted the code which you can use . It is worked on case function which will check if the length is less than 4 than if it is the it will put 0 if not it will calculate len -4
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

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 …
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

628 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