Solved

SQL error

Posted on 2014-10-16
4
132 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

14 Experts available now in Live!

Get 1:1 Help Now