Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Invalid length passed to the right function

Author  Topic 

Villanuev
Constraint Violating Yak Guru

478 Posts

Posted - 2014-03-18 : 03:08:44
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

478 Posts

Posted - 2014-03-18 : 04:31:13
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
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2014-03-18 : 07:41:00
[code]-- 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],[/code]


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

Villanuev
Constraint Violating Yak Guru

478 Posts

Posted - 2014-03-19 : 01:49:14
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
   

- Advertisement -