Solved

SQL error

Posted on 2014-10-16
4
128 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
  • 3
4 Comments
 
LVL 15

Expert Comment

by:Haris Djulic
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

762 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

12 Experts available now in Live!

Get 1:1 Help Now