Solved

SQL error

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

680 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