SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Invalid length passed to the right function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Villanuev
Constraint Violating Yak Guru

441 Posts

Posted - 03/18/2014 :  03:08:44  Show Profile  Reply with Quote
Hi,

I have an ssrs report when running the report i got this error.
while the codes running outside of ssrs i dont have any problem. thank you.

CASE WHEN Len(I.ITEMID) = 7 Then 'OEM'
         ELSE  Cast(Right(I.ITEMID, Len(I.ITEMID)-7) AS NVARCHAR(50))
    END AS STATUS,

Villanuev
Constraint Violating Yak Guru

441 Posts

Posted - 03/18/2014 :  04:31:13  Show Profile  Reply with Quote
This is the itemid that got an error.

cannot read the next data row, invalid length parameter passed to the right function

--Itemid--
GEN1020-R

--The result should be
-R

Edited by - Villanuev on 03/18/2014 04:32:00
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30241 Posts

Posted - 03/18/2014 :  07:41:00  Show Profile  Visit SwePeso's Homepage  Reply with Quote
-- Option 1
CASE LEN(i.ItemID)
	WHEN 7 THEN 'OEM'
        ELSE CAST(SUBSTRING(I.ItemID, 8, 50) AS NVARCHAR(50))
    END AS [Status],

-- Option 2
CASE LEN(i.ItemID)
	WHEN 7 THEN 'OEM'
        ELSE CAST(STUFF(I.ItemID, 1, 7) AS NVARCHAR(50))
    END AS [Status],



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

Villanuev
Constraint Violating Yak Guru

441 Posts

Posted - 03/19/2014 :  01:49:14  Show Profile  Reply with Quote
Thank you very much SwePeso.
May I know what is the error of my codes? Before it was running but yesterday, i got an error.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000